+ 2

Why character 'd' does not get joined to last element of the list in the below code..?

l = ['a', 'b', 'c'] print ('d'.join(l)) Output : adbdc https://code.sololearn.com/co2m89hO5CKB/?ref=app

23rd Nov 2020, 10:14 AM
Yathindra S
Yathindra S - avatar
5 Réponses
+ 4
Yathindra S. Join() is used to join the elements in a list. Since u tried joining d , it joined the elemnts of the list by being in between them. Check this thread 👇 https://www.sololearn.com/Discuss/1744468/?ref=app
23rd Nov 2020, 10:33 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 1
That's just how join works. You can append 'd' at the end with + 'd' if you need
23rd Nov 2020, 10:22 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Hello Benjamin, I'm still confused If 'd' is getting joined with first two elements of list... why that doesn't get joined to last element..?
23rd Nov 2020, 10:27 AM
Yathindra S
Yathindra S - avatar
0
The joins are only between the elements Read your example as "join elements of list l using 'd'
23rd Nov 2020, 10:30 AM
Benjamin Jürgens
Benjamin Jürgens - avatar