Exam PCAP All QuestionsBrowse all questions from this exam
Question 126

Assuming that the code below has been executed successfully, which of the expressions evaluate to True? (Choose two.)

    Correct Answer: A, C

    In the Class definition, 'var' is a class variable. Class variables are stored in the class's __dict__, so 'var' in Class.__dict__ evaluates to True. When an instance of the class is created with Object = Class(2), the instance variable 'prop' is added to Object's __dict__. Since only 'prop' is added to Object's __dict__, len(Object.__dict__) == 1 evaluates to True.

Discussion
macxszOptions: AC

A. 'var' in Class.__dict__ C. len(Object.__dict__) == 1

seaverickOptions: AC

class Class: var=1 def __init__(self,value): self.prop=value Object=Class(2) print('var' in Object.__dict__) print('prop' in Class.__dict__) print('var' in Class.__dict__) print(len(Object.__dict__)==1) print(Class.__dict__) print(Object.__dict__) AC