0

Some briefly describe me what is the work of return "\n".join([self.cont,line,other.cont])?

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)

6th Feb 2020, 2:39 AM
Shekhar Sharma
Shekhar Sharma - avatar
2 Respuestas
+ 3
Here return keyword is basically returning a value of __truediv__ join method of the string is used to join two strings. self.cont is spam variable string, line is = and number of = is equal to your other.cont length and other.cont is hello variable string. and then print function giving output on the console.
6th Feb 2020, 2:57 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
The the .join joins the list into a string, and with the "\n", it is saying that for every element, join it and add the \n escape character.
6th Feb 2020, 2:55 AM
KnuckleBars
KnuckleBars - avatar