Bird
0
0

Which of the following is the correct syntax to change the attribute age of an object person to 30?

easy📝 Syntax Q12 of 15
Python - Classes and Object Lifecycle
Which of the following is the correct syntax to change the attribute age of an object person to 30?
Aperson["age"] = 30
Bperson.age = 30
Cperson->age = 30
Dperson.age(30)
Step-by-Step Solution
Solution:
  1. Step 1: Recall attribute assignment syntax

    To modify an attribute, use dot notation with assignment: object.attribute = value.
  2. Step 2: Apply to given object and attribute

    Set person.age to 30 by writing person.age = 30.
  3. Final Answer:

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

    Assign attribute with dot and equals = person.age = 30 [OK]
Quick Trick: Use dot and equals to set attribute: obj.attr = value [OK]
Common Mistakes:
  • Using brackets like person["age"] = 30
  • Using arrow notation person->age = 30
  • Trying to call attribute like a function person.age(30)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes