+ 1
Logic
a="False" b="True" if bool(a)==bool(b): print(bool(a)) print(bool(b))
3 Answers
+ 4
a and b are both strings.
A string is True if it 'exists', that means, if it is not just ''.
Often for example you take input from the user, and if he doesn't enter anything, you want to do something, for example break out of a loop.
Then you would like to write something like:
while True:
word = input()
somelist.append(word)
if not word:
break
To make this possible, an empty string must be False, and everything else True.
So your code is a sort of 'trap': If you take only a quick look, you think, wait, one of these variables is False.
But it isn't False, it is 'False' - and that is True. ;-)
+ 5
What's your question?
+ 1
logic used in this question.why the output is true trur Valen.H. ~