Question 183 of 169
PCAP Object-Oriented Programming Practice Question
Which TWO of the following statements about class attributes in Python are true?
⚠ Common exam trap
The PCAP exam often tests the subtle distinction between mutating a mutable class attribute (which affects all instances) and reassigning it via an instance (which creates a shadowing instance attribute), leading candidates to incorrectly think that any modification via an instance changes the class attribute for all instances.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Class attributes are shared by all instances.
Class attributes are defined directly in the class body and are shared across all instances of that class. When you access a class attribute via any instance, Python looks up the attribute in the class's __dict__ if it is not shadowed by an instance attribute, ensuring all instances see the same value unless explicitly overridden.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Class attributes are always immutable.
Why it's wrong here
A class attribute is simply a name bound to an object in the class namespace; nothing in Python prevents that object from being mutable. You can attach any value, including a list, dict, or set, all of which support in-place changes. For example, assigning `tags = []` in a class body creates a shared mutable list, and calling `obj.tags.append('x')` mutates that list. Thus, immutability is a property of the referenced object, not of the class attribute mechanism itself.
- ✓
Class attributes are shared by all instances.
Why this is correct
Because class attributes live in the class's own namespace, the same object is visible to every instance of that class. When you access `inst.x`, Python first checks the instance's `__dict__`, then walks the class MRO, so if no instance-level attribute shadows it, all instances resolve to the identical class attribute. This shared visibility is the defining trait that distinguishes class attributes from instance attributes, which are stored per-object in each instance's `__dict__`.
- ✗
Class attributes are defined inside methods.
Why it's wrong here
Class attributes are introduced by assignments executed directly in the class body, immediately after the class statement starts; they are not created by code written inside method definitions. An assignment like `self.value = 1` inside a method creates (or replaces) an instance attribute, while a bare `value = 1` inside the method is merely a local variable with no effect on the class. Methods can read or modify class attributes through `ClassName.attribute` or `self.__class__.attribute`, but defining them is not their job.
- ✗
Modifying a class attribute via an instance modifies it for all instances.
Why it's wrong here
The statement confuses two very different operations. If you execute `instance.attr = new_value`, Python binds a new attribute in that instance's `__dict__`, shadowing the class attribute for that instance only—the class-level binding is untouched. However, if the class attribute points to a mutable object, an in-place change like `instance.items.append(item)` mutates the shared object and is visible everywhere, but that is mutation, not reassignment. The claim as written describes reassignment behavior, which is incorrect because it does not propagate to other instances or the class.
- ✓
Class attributes can be accessed via the class name.
Why this is correct
Because class attributes are stored in the class's namespace, they can always be referenced by the fully qualified class name, such as `ClassName.attribute`, regardless of whether any instance exists. This is the standard way to read class-level state explicitly and also the way to change it globally via `ClassName.attribute = new_value`. Instance access `instance.attribute` is simply a convenient fallback that ultimately resolves to the same class object through the `type` of the instance.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jul 4, 2026
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.