The right way to declare multiple variables in Python

preview_player
Показать описание
Python declare multiple variables

basic multiple declaration in python

x, y, z = None, None, None
x, y, z = 1, 2, 3
x, y, z = 1, '2', ['I''m a list']
x, y = True, True

advanced declaration of many variables

x = y = z
x = y = z = 1
x = y = z = ['x']
x, y, z = True

misleading usage of multiple variables

x = y = z = ['x']
print(x, y, z)
print(x, y, z)
print(x, y, z)

common errors:

- ValueError: not enough values to unpack (expected X, got Y)
- TypeError: 'int' object is not iterable
- ValueError: too many values to unpack (expected X)
Рекомендации по теме
join shbcf.ru