Join function - String | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Join function - String

print("* ".join(["spam", "eggs", "ham"])) Why ham is not changed?

17th Oct 2020, 7:17 PM
Bojan Jovanovic
Bojan Jovanovic - avatar
3 Answers
+ 8
join() only puts the string given between elements. Since ham is the last one, nothing gets put in after it.
17th Oct 2020, 7:25 PM
Russ
Russ - avatar
+ 3
Because split() splits a string into a list (hence the name) with the string provided as the separator. If you did print("spam, eggs, ham".split(", ")) you would get ['spam', 'eggs', 'ham']
17th Oct 2020, 8:14 PM
Russ
Russ - avatar
+ 1
print("spam, eggs, ham".split("* ")) why this code doesn't print spam* eggs* ham ?
17th Oct 2020, 7:58 PM
Bojan Jovanovic
Bojan Jovanovic - avatar