Certified Associate in Python Programming (PCAP-31-03) — Question 70

What is the expected output of the following code?

import sys
import math

b1 = type(dir(math)[01]) is str
b2 = type(sys.path[-1]) is str
print(b1 and b2)

Answer options

Correct answer: B

Explanation

The code checks if the first item in the list returned by dir(math) is a string and if the last item in sys.path is also a string. Both conditions are true, so the result of the logical AND operation is True. The other options do not reflect the actual output of the code.