Logic | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Logic

a="False" b="True" if bool(a)==bool(b): print(bool(a)) print(bool(b))

30th Oct 2018, 11:10 AM
AMAN TOMAR
AMAN TOMAR - avatar
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. ;-)
30th Oct 2018, 11:26 AM
HonFu
HonFu - avatar
+ 5
What's your question?
30th Oct 2018, 11:14 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
logic used in this question.why the output is true trur Valen.H. ~
30th Oct 2018, 11:24 AM
AMAN TOMAR
AMAN TOMAR - avatar