Exam PCAP-31-03 All QuestionsBrowse all questions from this exam
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)

    Correct Answer: B

    The given code checks the types of dir(sys) and sys.path[-1]. The dir(sys) function returns a list of strings representing the attributes of the sys module, hence the type of dir(sys) is list, not str, making b1 false. The second check, sys.path[-1], retrieves the last element in the sys.path list, which is a string by default, so b2 is true. Since b1 is false and b2 is true, the expression (b1 and b2) evaluates to false.

Discussion
DKAT2023Option: B

b1 type(dir(sys)) is list not str, so False and True = True