Bird
0
0

Which of these statements correctly modifies the attribute age of an object person to 30?

easy📝 Conceptual Q2 of 15
Python - Methods and Behavior Definition
Which of these statements correctly modifies the attribute age of an object person to 30?
Aperson.age = 30
Bperson.set_age(30)
Cage = 30
Dperson['age'] = 30
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute assignment syntax

    In Python, to change an attribute, use dot notation: object.attribute = value.
  2. Step 2: Check each option

    person.age = 30 uses correct syntax. person.set_age(30) assumes a method exists, which is not guaranteed. age = 30 assigns a variable, not an attribute. person['age'] = 30 uses dictionary syntax, invalid for normal objects.
  3. Final Answer:

    person.age = 30 -> Option A
  4. Quick Check:

    Modify attribute = object.attribute = value [OK]
Quick Trick: Use dot notation to change object attributes directly [OK]
Common Mistakes:
  • Using dictionary syntax on objects
  • Assigning to a variable instead of attribute
  • Assuming setter methods exist without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes