Python Forum
str.join()? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: str.join()? (/thread-30323.html)



str.join()? - Skaperen - Oct-16-2020

i saw some code that used str.join() for something. is that a normal join?


RE: str.join()? - Gribouillis - Oct-16-2020

It can work
>>> str.join('a', 'bc')
'bac'



RE: str.join()? - buran - Oct-16-2020

With str.join() you call instance method directly on the class. It expects to implicitly receive instance of the class - that will be used as separator and an iterable, whose elements will be concatenated with the use of the separator

that's why @Griboulis example
str.join('a', 'bc') # 'a' is the instance of str and 'bc' is the iterable

is identical with
'a'.join('bc')
and yield the same output.


RE: str.join()? - Skaperen - Oct-16-2020

i guess i need to use ''.join() since i was trying to make a string out of an iterator the yielded strings.