[0:00]Check out this feature in Python. Here we have a custom class called CustomStr, and it takes an initializer with a value which should be some sort of string. Now imagine you wanted to find some sort of multiplication functionality for this class. Well, we can do that using the method. And all it takes is some other thing that you want to multiply. Now, inside here we're going to try to return the float of our value times other. Otherwise, we're going to print that we could not multiply that value. But you can insert whatever kind of logic you want inside here. Next, we're going to create a custom string, and this will contain the string of 50, and we're going to multiply this object by five. So, as an output, we should get 250 because 5 * 50 is 250. But if we were to try to multiply the string of hello, we will get an error that we could not multiply hello. And it's also going to return none because this doesn't return anything.

You Can Multiply ANYTHING In Python With THIS Magic Method #programming #code #python
Indently
59s178 words~1 min read
Auto-Generated
Watch on YouTube
Share
MORE TRANSCRIPTS


