O‘zlashtirish operatorlari
Belgilash operatorlari
O‘zgaruvchilarga qiymatlarni belgilash uchun tayinlash operatorlari ishlatiladi:
| Operator | Misol | Ekvivalenti | Try it |
|---|---|---|---|
| = | x = 5 | x = 5 | Try it » |
| += | x += 3 | x = x + 3 | Try it » |
| -= | x -= 3 | x = x - 3 | Try it » |
| *= | x *= 3 | x = x * 3 | Try it » |
| /= | x /= 3 | x = x / 3 | Try it » |
| %= | x %= 3 | x = x % 3 | Try it » |
| //= | x //= 3 | x = x // 3 | Try it » |
| **= | x **= 3 | x = x ** 3 | Try it » |
| &= | x &= 3 | x = x & 3 | Try it » |
| |= | x |= 3 | x = x | 3 | Try it » |
| ^= | x ^= 3 | x = x ^ 3 | Try it » |
| >>= | x >>= 3 | x = x >> 3 | Try it » |
| <<= | x <<= 3 | x = x << 3 | Try it » |
| := | print(x := 3) | x = 3 print(x) |
Try it » |
Morj operatori
Python 3.8 "morj operatori" sifatida tanilgan := operatorini taqdim etdi. U o‘zgaruvchilarga qiymatlarni kattaroq ifodaning bir qismi sifatida belgilaydi:
Misol
Count o‘zgaruvchisi if operatorida tayinlangan va 5 qiymati berilgan:
numbers = [1, 2, 3, 4, 5]
if (count := len(numbers)) > 3:
print(f"List has {count} elements")
O‘zingiz sinab ko‘ring »
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
