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

Резултати

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

Пребарај: #goals

当前筛选 #goals清除筛选
Luxury Lifestyle

@luxury_lifestyle_billionaire_hub · Post #6902 · 10.07.2020 г., 15:30

🌈Only 19 Sian Roadster will be made 💰 . All sold out 💰😍 #Luxury#Goals 📷octavius_92 ❤️🔜 LuxurySuperCars ✅🔜@R_Group_Official ━━━━━━━━━━━━━━━━━

Pensive|

@PensivePost · Post #5365 · 17.08.2021 г., 04:45

When it's time to reach my goal it requires so many sacrifices so my heart always whispers to my soul. But one thing I would like to remind myself is Nothing changes, if Nothing changes...! #review #goals

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40613 · 31.01.2026 г., 23:01

As you may have noticed one month into the new year, traditional New Year’s resolutions often fail because people set vague or too big goals, rely only on willpower, and don’t have a clear plan. Small, specific changes and building habits step by step are supposed to work better. 🔄 [Read more] @googlefactss #NewYearsResolutions#Habits#Goals#SelfImprovement

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40880 · 30.03.2026 г., 22:01

Self-control is not just about willpower. 🧠 Building habits and routines makes it easier to stick to your goals. Repeating small positive actions regularly strengthens your ability to maintain self-discipline over time. Setting up your environment to make good choices easier and temptations harder also helps. After about three months, actions that once felt difficult can start to feel natural. 🔁🏃‍♂️🧩📊 [Read more] @googlefactss #psychology#selfcontrol#habits#goals#science#mindset If you have ideas or feedback contact us: @Googlefactss_Feedback_bot