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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Hello
Explanation: `__str__` method is called when printing the object, so 'Hello' is printed.
Explanation by: Mr. Dubey
`__str__` method is called when printing the object, so 'Hello' is printed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
81
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
80%
Success Rate