Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

What are magic methods in Python?
A. Ways to overload operators
B. Methods that are automatically called
C. All of the above
D. Special methods with double underscores (dunder)
Direction: Choose the correct option

Q2.

Which magic method is called when an object is created?
A. __new__
B. __call__
C. __init__
D. __init__ and __new__
Direction: Choose the correct option

Q3.

What does `__str__` do?
A. Called by `print()`
B. Returns a readable string representation of an object
C. Returns a representation for developers
D. Called by `repr()`
Direction: Choose the correct option

Q4.

What is the difference between `__str__` and `__repr__`?
A. `__repr__` is for end users
B. `__repr__` is for unambiguous representation, `__str__` for readable
C. `__str__` is for developers
D. They are the same
Direction: Choose the correct option

Q5.

Which magic method is called when you use `len(obj)`?
A. __size__
B. __length__
C. __count__
D. __len__
Direction: Choose the correct option

Q6.

What does `__call__` do?
A. Called when object is deleted
B. Called when attribute is accessed
C. Called when object is created
D. Allows an instance to be called like a function
Direction: Choose the correct option

Q7.

How do you make an object iterable?
A. Define `__iter__` and `__next__`
B. Define `__getitem__`
C. Define `__iter__` only
D. Define `__next__` only
Direction: Choose the correct option

Q8.

Which magic method is called when an attribute is accessed?
A. Both A and B
B. __getattribute__
C. __getattr__
D. __access__
Direction: Choose the correct option

Q9.

What does `__enter__` and `__exit__` define?
A. Iterator protocol
B. Context manager protocol
C. Descriptor protocol
D. Metaclass
Direction: Choose the correct option

Q10.

How do you define equality between objects?
A. Define `__cmp__`
B. Define `__eq__` method
C. Define `__eq__` method
D. Define `__compare__`