Basic Python Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Basic Python Question

Guys this code is working, the output is 0: x=5 y=False print(x*y) So I tried this code: x=int(input()) y=bool(input()) print(x*y) I used the input as: x=5 y=False I was expecting output to be 0. But it was 5. I didn't really get it. False means 0. So 5*0 has to be 0. Can you please explain why the output is 5?

17th Jan 2022, 7:48 PM
Ork
2 Answers
+ 2
Your argument to bool() is a string by input function, not a False boolean value. Try y = bool( False) #y = False bool("False") returns True.
17th Jan 2022, 7:56 PM
Jayakrishna 🇮🇳
+ 1
input() function returns a string, in your case it will be: - In the first input x input() returns "5" which is the argument to int() function that will convert to an integer x=int("5") -> x=5 - In the second input y input() returns "False" which is the argument to bool() function that will convert to a boolean. In this case "False" (a string) is not a none value that implies converting to True otherwise False y=bool("False") -> y=True So the output of your print(5*True) or print(5*1) will be 5. I hope this helps you to understand better.
17th Jan 2022, 9:01 PM
CLAD
CLAD - avatar