0
Why do you need to put "\n" in this magic method?
Why do you need a "\n" when doing this class magic method? 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)
3 Réponses
+ 3
"join" appends to "self.cont" "line" and "other.cont" through the character "\n" - a new line.
+ 2
Yes
0
so "\n" means a new line?