Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is operator overloading?

View

Which magic method is used to overload the + operator?

View

What is the result of this code?

View

Which of the following operators can be overloaded?

View

What is the use of the __str__() method?

View

Which operator does __eq__() overload?

View

Can comparison operators like >= be overloaded in Python?

View

What will __len__() return if overloaded?

View

What is the output of the following code?

View

Which operator cannot be overloaded in Python?

View

What is operator overloading?

Using operators outside functions
Defining custom behavior for operators with user-defined types
Replacing operators with functions
Using the same operator in different contexts

Which magic method is used to overload the + operator?

__add__()
__plus__()
__sum__()
__combine__()

What is the result of this code?

class A: def __init__(self, value): self.value = value def __add__(self, other): return self.value + other.value a = A(5) b = A(10) print(a + b)

15
Error
510
None

Which of the following operators can be overloaded?

+
-
*
All of the above

What is the use of the __str__() method?

To overload the print() function
To provide a string representation of the object
To compare objects
To initialize an object

Which operator does __eq__() overload?

=
==
!=
<

Can comparison operators like >= be overloaded in Python?

Yes
No
Only for primitive types
Only inside classes with abstract methods

What will __len__() return if overloaded?

Number of attributes in an object
Length of an object’s string representation
Length of a sequence or collection object
Size in bytes of the object

What is the output of the following code?

class A: def __str__(self): return "Object A" obj = A() print(obj)

Object A
Error
None
<__main__.A object>

Which operator cannot be overloaded in Python?

+
*
is
/