Bird
0
0

Which of the following is the correct syntax to add a custom attribute height with value 180 to an object person?

easy📝 Syntax Q3 of 15
Python - Custom Exceptions
Which of the following is the correct syntax to add a custom attribute height with value 180 to an object person?
Aperson->height = 180
Bperson[height] = 180
Cperson.height(180)
Dperson.height = 180
Step-by-Step Solution
Solution:
  1. Step 1: Identify valid Python syntax for attribute assignment

    Python uses dot notation to assign attributes: object.attribute = value.
  2. Step 2: Check each option's syntax

    person.height = 180 uses correct dot notation. person->height = 180 uses arrow operator which is invalid in Python. person.height(180) tries to call attribute as a function. person[height] = 180 uses dictionary syntax without quotes, invalid for objects.
  3. Final Answer:

    person.height = 180 -> Option D
  4. Quick Check:

    Dot notation for attributes = person.height = 180 [OK]
Quick Trick: Use dot notation, not arrow or brackets, for attributes [OK]
Common Mistakes:
  • Using arrow operator from other languages
  • Calling attribute like a function
  • Using brackets without quotes on objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes