0

Understanding how join() with lists, and format() works

I would like some further insight in how the function join() works differently when using format(), and a list. As you can tell in the bottom, output is very different. Before thank you. ina = "{a}{aa}{aaa}{aaaa}".format(a = "This ", aa = "is ", aaa = " my", aaaa = " house.") print("=".join(ina)) list = "_".join(["Mayor in", "is the", "one to, done"]) print(list) OUTPUT: T=h=i=s= =i=s= = =m=y= =h=o=u=s=e=. Mayor in_is the_one to, done

22nd Jun 2022, 4:32 AM
Jacob Barrientos
1 Réponse
+ 3
str.join(iterable) -> `iterable` can be a list of strings or string .. it puts that `str` between each two items. Eg. "-".join(["Hello","world","!"]) -> Hello-world-! And because string is a set of characters each character is an item Eg. "-".join("Hello!") -> H-e-l-l-o-!
22nd Jun 2022, 8:10 AM
Sousou
Sousou - avatar