Previous

Variables and Types

5 / 6
Next

Variables of type Boolean have two possible values: True and False. These are not strings, but Python keywords.

b = True
print(type(b)) # bool
s = "True"
print(type(s)) # str

Inputs can be cast to type bool, but be aware that strings "False" and "0" are cast to true. The only string that is cast to false is the empty string. Casting from ints to bools, 0 is the only falsy int.

s = "0"     # string "0"
n = int(s)  # int 0
b = bool(n) # bool False
Send

True or false

Hint
Beginner

Write a program that takes 0 or 1 as input. Print its Boolean representation.

Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!