PLEASE SUBSCRIBE!!!
In the previous lesson ( • Python Programming: Lesson 34 - Inher... ), we studied inheritance as a fundamental of object-oriented programming. Here, we use the _str_ function to implement a string representation of any object.
def __str__(self):
This function defines what it means to print an instance of a class
This is nice if we want a clean string representation that shows the values of
the instance variables for a particular object. It's up to us how we write it!
return self.name + " is " + self.age + " years old"
1:21 Review of Basic OOP
7:36 Review of Inheritance
12:53 NEW: Overriding Methods with the Same Set of Inputs
15:40 NEW: String Representation of an Object (__str__ Instance Method)
An equivalent Java lesson is available here: • Java Programming: Lesson 23 - Default...
What if we want to add or multiply two objects together? Check out dunders here, a neat new topic: • Python Programming: Lesson 36 - Magic... (lesson 36)
Thanks for watching, and PLEASE SUBSCRIBE!!!