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
Latest PCEP-30-02 Dumps Valid Version with 124 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund