0

Explanation of the metod 'join'

I got very confused with this so i left the python course for some days to study OOP in detail, i returned and i understand everything of this code except the 'join' method, it seems unique for clases but i dont now yet so.... what is exactly its function ? 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 Dec 2018, 7:26 PM
Razf
Razf - avatar
2 ответов
+ 6
It is not class-specific, it is a Python builtin that joins the array (list, dictionary, tuple or whatever you call it in python) with a joiner character \n and returns one joined string out of the many pieces you joined. "-".join(['a', 'b', 'c', 'd']) == "a-b-c-d"
24th Dec 2018, 7:35 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
Very thanks!!!!
24th Dec 2018, 8:21 PM
Razf
Razf - avatar