a, b, _ =1, 2, True
print(a, b)
Output :1 2
a = b = c =2
print(a, b, c)
b =345
print(a, b, c)
Output :
2 2 2
2 345 2
As expected , Change variables b Value , Only variables b The value of has changed .
The test list
x = y = [7, 8, 9]
print(x)
print(y)
x = [13, 88, 99]
print(x)
print(y)
Output :
[7, 8, 9]
[7, 8, 9]
[13, 88, 99]
[7, 8, 9]
As expected , Change list x The element value of , Only list x The value of has changed .
Change the value of an element in the column :
x = y = [7, 8, 9]
x[0] =789
print(x)
print(y)
Output :
[789, 8, 9]
[789, 8, 9]
Change list x The value of the first element , Class table y The first element is also modified .
Nested list
x = [1, 2, [3, 4, 5], 6, 7]
print(x)
print(x[2])
print(x[2][1])
Output :
[1, 2, [3, 4, 5], 6, 7]
[3, 4, 5]
4
a =2
print(a)
print(type(a))
a =‘New value’
print(a)
print(type(a))
Output :
2
<class ‘int’>
New value
<class ‘str’>
print(True +False ==1) # 1 + 0 == 1
print(True *True ==1) # 1 * 1 == 1
Output :
True
True