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)
2 Antworten
+ 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"
+ 1
Very thanks!!!!