QuestionQ23

VerifiedModules and Packages

What output is expected from the following code?

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

dir() returns a list of attribute names rather than a string, making b1 false. An and expression with a false first operand evaluates to False.

Community Discussion

No comments yet. Be the first to start the discussion!