My friend gave my this code in Python:
a ,= 1------1,
print(a)
The output is 2
. But why? Can somebody explain how it works?
My friend gave my this code in Python:
a ,= 1------1,
print(a)
The output is 2
. But why? Can somebody explain how it works?
a, = 1------1,
is the same as:
a = 1------1
1-(-(-(-(-(-1)))))
|+| |+| |+|
=> 1 + 1 = 1
You can think of this comma like this:
a = 1 # a is 1
a, = [1] # a is 1
a = [1] # a is [1]