Classes & Objects · Question 4 · Easy

Which special method does Python call automatically, right after an object is created, to set up its initial attributes?

  1. __str__
  2. __call__
  3. __del__
  4. __init__
Answer and explanation

Answer: D. __init__

Explanation: __init__ is the initialiser: it receives the new object as self along with the arguments given to the class. __str__ gives a readable string, __call__ makes an object callable and __del__ runs at clean-up.

Previous: The deposit method of an Account object is called twice. What does the second… · Next: Manager inherits from Employee and defines nothing of its own. What does…

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

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