Classes & Objects · Question 1 · Easy
A Student object is created and one of its attributes is updated. What does this code print?
class Student:
def __init__(self, name, marks):
self.name = name
self.marks = marks
s = Student("Riya", 82)
s.marks += 5
print(s.name, s.marks)
- Riya 82
- Riya 87
- name 87
- AttributeError
Answer and explanation
Answer: B. Riya 87
Explanation: __init__ stores the two values on the object. s.marks += 5 then updates that object's marks from 82 to 87.
Next: Inside a method defined in a class, what does the first parameter…
Practise classes & objects
Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.
More classes & objects questions
- Inside a method defined in a class, what does the first parameter…
- The deposit method of an Account object is called twice. What does the second…
- Which special method does Python call automatically, right after an object is…
- Manager inherits from Employee and defines nothing of its own. What does…
- Square overrides the area method of its parent Shape. What is printed for a…
- The method on() in the Lamp class is written without a self parameter. What…
- wheels is a class attribute of Car, and it is then assigned through one…
- The child class Student defines its own __init__ and does not call the…
- Three classes in a chain each extend fee() using super(). What does the last…
- The Point class defines __eq__. What do == and is give for two separately…
More python practice
Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge