Bird
Raised Fist0

What is a public attribute in a Python class?

easy🧠 Conceptual Q11 of Q15
Python - Encapsulation and Data Protection
What is a public attribute in a Python class?
AAn attribute that can be accessed and changed from outside the class
BAn attribute that is hidden and cannot be accessed outside the class
CA method that runs automatically when an object is created
DA special function to delete an object
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute visibility

    Public attributes are designed to be accessed and modified from outside the class.
  2. Step 2: Compare options

    An attribute that can be accessed and changed from outside the class correctly describes public attributes. Options A, B, and D describe other concepts.
  3. Final Answer:

    An attribute that can be accessed and changed from outside the class -> Option A
  4. Quick Check:

    Public attribute = accessible outside [OK]
Quick Trick: Public means anyone can access or change it [OK]
Common Mistakes:
MISTAKES
  • Confusing public with private attributes
  • Thinking methods are attributes
  • Mixing up constructors with attributes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes