A

Admin • 833K Points
Coach

Q. What will the following code print?

Code:
class A:
def __str__(self):
return "Hello"

obj = A()
print(obj)
  • (A) Hello
  • (B) A object at some memory location
  • (C) None
  • (D) Error
  • Correct Answer - Option(A)
  • Views: 28
  • Filed under category Python
  • Hashtags:

Explanation by: Admin

`__str__` method is called when printing the object, so 'Hello' is printed.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.