Why do you need to put "\n" in this magic method? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

24th Apr 2020, 8:26 PM
Ismael Browne
Ismael Browne - avatar
3 Answers
+ 3
"join" appends to "self.cont" "line" and "other.cont" through the character "\n" - a new line.
24th Apr 2020, 8:53 PM
Solo
Solo - avatar
+ 2
Yes
24th Apr 2020, 9:17 PM
Solo
Solo - avatar
0
so "\n" means a new line?
24th Apr 2020, 9:04 PM
Ismael Browne
Ismael Browne - avatar