PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 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)

Show Answer
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

1 comment
Sign in to comment
DKAT2023Option: B
Jul 12, 2024

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