Which of the variables will contain False?

Consider the following code snippet:

w = bool(23)

x = bool(”)

y = bool(‘ ‘)

z = bool([False])

Which of the variables will contain False?
A . z
B. x
C. y
D. w

Answer: B

Explanation:

Topic: type casting with bool()

Try it yourself:

print(bool(23)) # True

print(bool(”)) # False

print(bool(‘ ‘)) # True

print(bool([False])) # True

The list with the value False is not empty and therefore it becomes True

The string with the space also contain one character

and therefore it also becomes True

The values that become False in Python are the following:

print(bool(”)) # False

print(bool(0)) # False

print(bool(0.0)) # False

print(bool(0j)) # False

print(bool(None)) # False

print(bool([])) # False

print(bool(())) # False

print(bool({})) # False

print(bool(set())) # False

print(bool(range(0))) # False

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments