Bird
0
0

You have a class Student with attributes name and grades (a list). How do you add a new grade 95 to the student's grades list?

hard📝 Application Q8 of 15
Python - Classes and Object Lifecycle
You have a class Student with attributes name and grades (a list). How do you add a new grade 95 to the student's grades list?
Astudent.grades = 95
Bstudent.append(95)
Cstudent.grades.append(95)
Dstudent.grades.add(95)
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute type

    The grades attribute is a list, so to add an item, use the list method append().
  2. Step 2: Evaluate options

    student.grades.append(95) correctly calls append(95) on the grades list. student.grades = 95 overwrites the list with an integer. student.append(95) tries to call append on the student object, which is invalid. student.grades.add(95) uses a non-existent method add on list.
  3. Final Answer:

    student.grades.append(95) -> Option C
  4. Quick Check:

    Use list append to add items = student.grades.append(95) [OK]
Quick Trick: Use list methods on list attributes, not on the object [OK]
Common Mistakes:
  • Assigning a single value to list attribute
  • Calling list methods on the object instead of attribute
  • Using non-existent list methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes