Assuming that the code below has been executed successfully, which of the expressions evaluate to True? (Choose two.)
Assuming that the code below has been executed successfully, which of the expressions evaluate to True? (Choose two.)
Expressions 'data' in Class.__dict__ and 'Var' in Class.__dict__ evaluate to True. The first checks if 'data' is an attribute of the Class, which it is. The second checks if 'Var' is an attribute of the Class; given the typo correction, 'Var' is indeed an attribute of Class and hence also evaluates to True.
There is a typo in answer C. "var" should be capitalized "Var": class Class: Var = data = 1 def __init__(self,value): self.prop = value Object = Class(2) print(len(Class.__dict__) == 1) # False print("data" in Class.__dict__) # True print("Var" in Class.__dict__) # True print("data" in Object.__dict__) # False print(Class.__dict__) print("*************") print(Object.__dict__)
B (also C if 'Var')
BC is correct
>>> Object.__dict__ {'prop': 2} >>> Class.__dict__ mappingproxy({'__module__': '__main__', 'Var': 1, 'data': 1, '__init__': <function Class.__init__ at 0x100efd040>, '__dict__': <attribute '__dict__' of 'Class' objects>, '__weakref__': <attribute '__weakref__' of 'Class' objects>, '__doc__': None}) >>>
Correct Answer should be BC
for me BC is correct
Tested. BC
only correct answer is: B. 'data' in Class.__dict__ If it was 'Var' instead, also: C. 'var' in Class.__dict__
Correct Answer should be BC
The correct answer should be B and C
print(isinstance(obj_b,A)) # ans A, The isinstance() function returns True # if the specified object is of the specified type # return false print(A.VarA ==1) # ans B, A.VarA = 1, so A.VarA ==1. Then,it return true print(obj_a is obj_aa) # ans C, return false print(B.VarA == 1) # ans D, B.VarA = 2, so B.VarA not == 1. Then, it return false The correct answer should be B,C