Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 137 discussion

Actual exam question from Python Institute's PCAP
Question #: 137
Topic #: 1
[All PCAP Questions]

What is the expected behavior of the following code?

  • A. it outputs 2
  • B. it raises an exception
  • C. it outputs 1
  • D. it outputs 0
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
seaverick
10 months, 1 week ago
#question 137 class Class: Variable = 0 def __init__(self): self.value = 0 obj1 = Class() Class.Variable += 1 obj2 = Class() obj2.value += 1 print(obj2.Variable, obj2.value, Class.Variable, obj1.Variable,obj1.value) print(obj2.Variable + obj1.value) Tested: C
upvoted 2 times
...
stuartz
2 years, 5 months ago
Answer is C. Following shows interactions of class variables vs. instance variables >>> class Class: ... Var = 0 ... def __init__(self): ... self.value = 0 ... >>> obj1 = Class() >>> Class.Var += 2 >>> obj2 = Class() >>> Class.Var += 2 >>> obj1.Var += 5 >>> obj2.value += 1 >>> print(obj2.Var, obj2.value, Class.Var, obj1.Var) 4 1 4 9
upvoted 2 times
...
macxsz
2 years, 6 months ago
Selected Answer: C
C. it outputs 1
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...