Exam PCAP All QuestionsBrowse all questions from this exam
Question 76

What is the expected output of the following code?

    Correct Answer: C

    The `dir()` function returns a list of strings representing the names in the specified module's namespace. Therefore, `dir(math)[0]` is a string and `type(dir(math)[0]) is str` evaluates to `True`. The `sys.path` list contains strings representing the directories Python will search for modules, so `sys.path[-1]` is also a string and `type(sys.path[-1]) is str` evaluates to `True`. Therefore, the expression `b1 and b2` where both `b1` and `b2` are `True` evaluates to `True`.

Discussion
sadako11Option: C

dir(math) returns a list containing strings sys.path returns a list containing strings so the answer is C True

rocky48

>>> b1 = type(dir(math)[0]) is list >>> b2 = type(sys.path[-1]) is list >>> b1 False >>> b2 False >>> print(b1 and b2) Sorry the answer is False

rocky48

My bad, its checking for a list and not str, If it is checking for a str : Answer = True elseif checking for a list : Answer = False

macxszOption: C

C. True

rocky48Option: C

answer is C True

rocky48

>>> b1 = type(dir(math)[0]) is list >>> b2 = type(sys.path[-1]) is list >>> b1 False >>> b2 False >>> print(b1 and b2) Sorry the answer is False

rocky48

My bad its checking for a list and not str, If it is checking for a str : Answer = True elseif checking for a list : Answer = False

wacha1978Option: C

import sys import math print(dir(math)[0]) b1=type(dir(math)[0]) is str print(sys.path[-1]) b2=type(sys.path[-1]) is str print(b1 and b2 ) __doc__ /usr/lib/python3.7/site-packages True

zantrzOption: C

True import math print(dir(math)) print(type(dir(math))) # <class 'list'> print(type(dir(math)) is list) # True print(type(dir(math)[0])) # <class 'str'> print(type(dir(math)[0]) is str) # True import sys print(type(dir(sys.path))) # <class 'list'> print(type(dir(sys.path)) is list) # True print(type(dir(sys.path)[-1])) # <class 'str'> print(type(dir(sys.path)[-1]) is str) # True

cufta05Option: C

It should be False

cufta05

Sorry I meant A

Noarmy315Option: C

print(b1,b2,b1 and b2) #True True True

wacha1978Option: A

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