+ 1
object oriented programming #python #output
class SpecialString: def __init__(self, cont): self.cont = cont def __truediv__(self, other): line = "=" * len(other.cont) return "\n".join([self.cont, line, other.cont]) spam = SpecialString("spam") hello = SpecialString("Hello world!") print(spam / hello) Result: >>> spam ============ Hello world! >>>
3 Antworten
+ 4
Is this a question?
+ 1
truediv is a magic method which will be called on division (/) operation resulting in that output
0
how the output has come....?? the control flow of the python program...??
the "__truediv__(self,other)" is not called once....how the output is generated.??