πŸ“Š Python
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

πŸ‘οΈ
58
Total Visits
πŸ“½οΈ
8 mo ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
91%
Success Rate