Q. What happens if __str__() is not defined in a class?

  • (A) __repr__() is called as fallback
  • (B) Compilation error
  • (C) Returns empty string
  • (D) Program crashes
πŸ’¬ Discuss
βœ… Correct Answer: (A) __repr__() is called as fallback
Explanation: Python will fallback to __repr__() if __str__() is not defined.
Explanation by: Mr. Dubey
Python will fallback to __repr__() if __str__() is not defined.

πŸ’¬ Discussion


πŸ“Š Question Analytics

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