PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 102


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

Show Answer
Correct Answer: BC

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.

Discussion

11 comments
Sign in to comment
mazimirOptions: BC
Oct 19, 2021

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__)

Noarmy315Options: BC
Jan 2, 2022

B (also C if 'Var')

vlobachevskyOptions: BC
Oct 11, 2021

BC is correct

it_man_531Options: BC
Jan 31, 2022

>>> 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}) >>>

9prayerOptions: BC
Feb 5, 2023

Correct Answer should be BC

DTL001Options: BC
Dec 19, 2021

for me BC is correct

Angel75Options: BC
Feb 26, 2022

Tested. BC

macxszOption: B
May 4, 2022

only correct answer is: B. 'data' in Class.__dict__ If it was 'Var' instead, also: C. 'var' in Class.__dict__

JnanadaOptions: BC
Aug 19, 2022

Correct Answer should be BC

dicksonpwcOptions: BC
Apr 25, 2023

The correct answer should be B and C

dicksonpwcOptions: BC
Apr 25, 2023

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