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
1 Respuesta
+ 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-!