Certified Associate in Python Programming (PCAP-31-03) — Question 43
What is the expected output of the following code?
import sys
b1 type (dir(sys)) is str
b2 type (sys.path[-1]) is str
print (b1 and b2)
Answer options
- A. True
- B. False
- C. 0
- D. None
Correct answer: B
Explanation
The expected output is False because while 'type(dir(sys)) is str' evaluates to True, 'type(sys.path[-1]) is str' also evaluates to True, but the variable b1 is incorrectly defined. The logical 'and' operator requires both conditions to be True for the overall expression to be True, which is not the case here due to the syntax error in b1.