Bird
0
0

What does it mean when an attribute in a Python class is called public?

easy📝 Conceptual Q1 of 15
Python - Encapsulation and Data Protection
What does it mean when an attribute in a Python class is called public?
AIt is hidden and only accessible inside the class.
BIt can be accessed and modified from outside the class.
CIt cannot be accessed outside the class.
DIt is automatically private and needs special methods to access.
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute visibility in Python classes

    Public attributes are those that can be freely accessed and changed from outside the class instance.
  2. Step 2: Compare with other attribute types

    Private attributes start with underscores and are meant to be hidden, unlike public ones.
  3. Final Answer:

    It can be accessed and modified from outside the class. -> Option B
  4. Quick Check:

    Public attribute access = Allowed [OK]
Quick Trick: Public attributes have no leading underscore [OK]
Common Mistakes:
  • Confusing public with private attributes
  • Thinking public means read-only
  • Assuming public attributes need special methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes