+ 2
Please help me know why this code prints 50?? Shouldn't the answer be a boolean value?
a=50 b=100 print (a and b)
7 odpowiedzi
+ 5
Namit Jain
print("" and "wow" and "amazing")
an empty string evaluates to false. What's the output?
Please check the links (😁jk)
+ 4
It's not printing 50 it's printing 100.
See this to know why.
https://www.sololearn.com/discuss/2220489/?ref=app
Do some research on "short circuiting operands in python" to learn more.
Shivangi Agarwal I edited my answer.
Take a look at this too (topic 5.1 & 5.2) :
https://docs.python.org/2/library/stdtypes.html
That's python2 but for py3 it's almost the same thing.
Namit Jain Not exactly. Please go through the links given.
+ 4
Namit Jain
print(0 and 2 and 3)
0 evaluates to false. What's the output?
Please check the links😉
+ 3
'and' aways prints the second value
And 'or' prints the first value
+ 2
Yesss, thanks(you opened my eyes)
You are correct
But this rule will always work with strings right?
+ 2
Got a little, thanka
+ 1
Can u pls explain because acc to me 'and' will discard the first one(always) and consider the second one and it's opposite in 'or'
For example,
print(1 and 2 and 3)
Ouput: 3
print(1 and 2 or 3)
Ouput: 2
print((1 and 2) or 3)
Output: 2
print((1 or 2) and 3)
Output: 3