0

Help me explain this code plzz

p,p,p=1,2,3 print(p,p,p) #Output: #3 3 3

5th Jul 2021, 2:54 AM
TCorn
TCorn - avatar
4 ответов
+ 7
it's same as doing: p = 1 p = 2 p = 3
5th Jul 2021, 2:58 AM
visph
visph - avatar
+ 3
first line destructure tuple (1,2,3) in p for each values, so only last one remain in p...
5th Jul 2021, 2:58 AM
visph
visph - avatar
+ 3
When providing multiple value to a single variable, the variable only stores the last assigned value that's why p stores 3, and while printing only outputs 3 as value
5th Jul 2021, 3:56 AM
Sumit Kumar
Sumit Kumar - avatar
+ 1
p,p,p=1,2,3 is the same as: p=1 #assigned p variable value 1 p=2 #assigned p variable value 2 p=3 #assigned p variable value 3 #and now we print the same variable p just 3 times!
5th Jul 2021, 6:11 AM
Shadoff
Shadoff - avatar