Open Artinflamepurity opened 7 months ago
Fix: #42
In Python, truediv is used to overload the division operator (/), so when you use / between two SpecialString objects, this method is called instead of performing regular division.
What does it do?:
You create two objects: -> spam = SpecialString("spam"): This stores the string "spam" in the cont attribute of the spam object. -> hello = SpecialString("Hello world!"): This stores the string "Hello world!" in the cont attribute of the hello object.
When you use spam / hello, this calls the truediv method and does the following: -> It takes spam.cont, which is "spam". -> It calculates the length of hello.cont, which is "Hello world!", and creates a line of equal signs with that length. Since "Hello world!" is 12 characters long, line becomes "============". -> It joins spam.cont ("spam"), the line of equal signs ("============"), and hello.cont ("Hello world!"), separating them with newlines.
print(spam/Hello) is basically print(spam.truediv(hello))
Hello world!
class SpecialString: def init(self, cont): self.cont = cont
spam = SpecialString("spam") hello = SpecialString("Hello world!") print(spam / hello)