string formatting in python.............?? HOW | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

string formatting in python.............?? HOW

print(", ".join(["spam", "eggs", "ham"])) OUTPUT "spam, eggs, ham" # ( , ) is already a part of string so what does the join() do..?? print("spam, eggs, ham".split(", ")) #prints "['spam', 'eggs', 'ham']

6th Apr 2018, 7:14 PM
Smriti Rastogi
Smriti Rastogi - avatar
3 Réponses
+ 1
I see it created one string out of three. What do you want the output to look like?
6th Apr 2018, 7:49 PM
Igor Matić
Igor Matić - avatar
0
", ".join puts (, ) between the elements. if you want the elements to be fully merged, delete both comma and space. "".join()
6th Apr 2018, 7:53 PM
Igor Matić
Igor Matić - avatar
0
hii
21st Jan 2020, 4:58 AM
Aman Shaw