Certified Associate in Python Programming (PCAP-31-03) — Question 92
What is the expected output of the following code?
import sys
import math
b1 = type(dir(math)[0]) is str
b2 = type(sys.path[-1]) is str
print(b1 and b2)
Answer options
- A. False
- B. True
- C. 0
- D. None
Correct answer: B
Explanation
The expression 'type(dir(math)[0]) is str' evaluates to True because the first element of the list returned by dir(math) is indeed a string. Similarly, 'type(sys.path[-1]) is str' also evaluates to True since the last element of sys.path is a string. Therefore, the logical 'and' operation results in True. The other options are incorrect as they do not reflect the combined truthiness of both expressions.