Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.join()?
#1
i saw some code that used str.join() for something. is that a normal join?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It can work
>>> str.join('a', 'bc')
'bac'
Reply
#3
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.
metulburr likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
i guess i need to use ''.join() since i was trying to make a string out of an iterator the yielded strings.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020