[Tutor] joining strings using arrays and string variables.

mhysnm1964 at gmail.com mhysnm1964 at gmail.com
Sun Feb 7 06:06:39 EST 2021


All,

 

A really basic question. 

 

If I want to join a list that has a maximum of 5 elements plus two strings
variable. The below doesn't seem to work:

 

>>> a = ['hello','fred','and','tom']


>>> b = '/'.join(['welcome', 'the', 'following', a])


Traceback (most recent call last):


  File "<stdin>", line 1, in <module>


TypeError: sequence item 3: expected str instance, list found


>>> b = '/'.join('welcome', 'the', 'following', a)


Traceback (most recent call last):


  File "<stdin>", line 1, in <module>


TypeError: join() takes exactly one argument (4 given)


 

How can you do the above?

 

 

Sean 



More information about the Tutor mailing list