- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the str() function do in Python Object Oriented Programming?
The __str__ method
__str__ is a special method, like __init__, that returns a 'informal' string representation of an object. It is useful in debugging.
Consider the following code that uses the __str__ method
class Time: def __str__(self): return '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
When we print an object, Python invokes the str method −
>>> time = Time(7, 36) >>> print time 07:36:00
- What does the repr() function do in Python Object Oriented Programming?
- What does the cmp() function do in Python Object Oriented Programming?
- Object Oriented Programming in Python?
- What is Data Hiding in Python Object Oriented Programming?
- Python Object-oriented and Functional Programming
- What is object-oriented programming (OOP)?
- What is the difference between Object oriented programming and Object based programming?
- What are basic Object oriented programming concepts?
- Object Oriented language v/s Procedure oriented programming language.
- How to start object-oriented programming in C++?
- Object Oriented language v/s Object based programming language.
- Basic Concepts of Object Oriented Programming using C++
- What does reload() function do in Python?
- What does raw_input() function do in python?