Lesson-06 | __str__ and __repr__ | [OOP in Python]

Опубликовано: 12 Октябрь 2024
на канале: Learning Orbis
4,167
74

This is the lesson number 06 of the lesson series on Object Oriented Programming (OOP) in Python. It will be a complete course with the aim is to cover almost everything needed in Object Oriented Programming.
In this lesson we will see the use of two special methods; _str_ and _repr_ to represent the object of the class.

Link to complete playlist:
   • Object-Oriented Programming in Python  

Lesson Code:
https://github.com/MAN1986/OOP-in-Pyt...



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Review Questions of the Lesson


1. You must have used the function str() to convert a data type to string e.g. if x is of int data type, we can use str(x) to convert it to a string. How this str() related to _str_ special method?
2. Use datetime module and create an object of datetime or time class (You can search how to create these objects). Then print that object in two ways; directly using print() and then using repr(). Verify the difference as mentioned in the lesson and show the output corresponding to both

#OOP #ObjectOrientedProgramming #Python