+ 1

Explain this code

a=0 or 1 b=0 or 2 c=a or b print (a+b+c) Output--------------------- 4

3rd Oct 2020, 4:09 PM
Vishal Kumar Bhagat
Vishal Kumar Bhagat - avatar
2 Answers
+ 3
The "or" operator basically returns a truthy value among the two given values(Truthy value can be anything except 0, None, etc) So the variable a is assigned 1(truthy value) Variable b is 2(truthy) And c is assigned 1(both values are truthy but 1 is specified before 2) And a+b+c will equal 1+2+1 which is 4 And so it prints 4
3rd Oct 2020, 5:27 PM
anon
0
Why not take the value of a = 0
3rd Oct 2020, 5:31 PM
Vishal Kumar Bhagat
Vishal Kumar Bhagat - avatar