TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #156 · 2 окт.

Те, кто в Python не первый день, хорошо знают, что на число можно умножить не только число, но и другие типы. Главное, чтобы у этих типов была реализация такой операции. # list >>> [1] * 3 [1, 1, 1] # tuple >>> (2, 3) * 3 (2, 3, 2, 3, 2, 3) # string >>> "A" * 3 "AAA" Так работает полиморфизм стандартных типов. Интересно здесь то, что это сработает и в том случае, когда порядок операндов обратный. То есть int умножить на [тип]. # list >>> 3 * [1] [1, 1, 1] # tuple >>> 3 * (2, 3) (2, 3, 2, 3, 2, 3) # string >>> 3 * "A" "AAA" Если хотите реализовать такое поведение в ваших классах то следует помнить два момента: 1. Если множитель справа, то вам нужно реализовать метод __mul__, наш класс это первый операнд, то есть слева. myType * 3 2. Если множитель слева, то вам нужно реализовать метод __rmul__, наш класс это второй операнд, справа. 3* myType Всё тоже самое можно делать и для других математических операторов. И если в этом примере действие и результат будут фактически одинаковыми, то бывают ситуации, когда это не так. Например, при умножении матриц имеет значение порядок операндов. Для других операторов, таких как деление или сдвиг, очень важно кто с какой стороны находится. >>> 2/4, 4/2 (0.5, 2.0) >>> 2<<3, 3<<2 (16, 12) >>> 100%15, 15%100 (10, 15) #tricks#basic

Резултати

Пронајдени 2 слични објави

Пребарај: #mofa

当前筛选 #mofa清除筛选
Addis Standard

@addisstandardeng · Post #21089 · 16.01.2026 г., 07:31

News: #Ethiopia, #India agree on visa-free travel for diplomats, say work has begun on sensitive foreign ministry data center Ethiopia and India have signed an implementation agreement granting mutual visa-free travel for holders of diplomatic passports and announced that work has begun on a highly sensitive data center project for Ethiopia’s Ministry of Foreign Affairs (#MoFA), underscoring a deepening of bilateral cooperation. The agreement on the exchange of diplomatic notes was signed on January 15, 2025, at the Indian Embassy in Addis Abeba by Anil Kumar Rai, Ambassador of India to Ethiopia and Permanent Representative to the African Union, and Ambassador Dewano Kedir, Director General for Middle East, Asia, and Pacific Affairs at Ethiopia’s Ministry of Foreign Affairs. Ambassador Rai confirmed that work on the data center for Ethiopia’s Ministry of Foreign Affairs is already underway. “The data center for the Ministry of Foreign Affairs will be .... Read more: https://addisstandard.com/?p=54595

Vet_opportunities

@vet_opportunities · Post #63 · 19.07.2025 г., 07:15

➡️ውጭ ጉዳይ ሚኒስቴር 𝐂𝐚𝐥𝐥 𝐅𝐨𝐫 𝐕𝐨𝐥𝐮𝐧𝐭𝐞𝐞𝐫𝐬! 🔗https://forms.gle/34PxUgPV2bgcZCbU9 #MOFA#Volunteers #JOIN#Share ማድረጋችሁን አትርሱ👇👇 @vet_opportunities @vet_opportunities