Search Header Logo

Quiz on Magic Methods in Python

Authored by NOR (PMJ)

Computers

University

Used 2+ times

Quiz on Magic Methods in Python
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What are magic methods in Python also known as?

Private methods

Dunder methods

Public methods

Static methods

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which magic method is used to initialize a new instance of a class?

__new__

__init__

__del__

__call__

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the __str__ method do in Python?

Converts an object into an integer

Returns a string representation of an object

Deletes an object

Compares two objects

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of the __getitem__ method?

To retrieve an item using an index

To delete an item

To modify an attribute

To add two numbers

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which magic method allows an object to be used as a boolean value?

__bool__

__int__

__float__

__str__

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the function of the __del__ method?

It initializes an object

It deletes an object when it is no longer in use

It modifies an object

It compares two objects

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which magic method is used for the * operator in a class?

__mul__

__truediv__

__mod__

__sub__

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?