What should this
What do you want to achieve?
If you want to concatenate the items in the list to a
Unpacking arguments in function signature:
Unpacking keyword arguments in function signature:
*
expression do?What do you want to achieve?
If you want to concatenate the items in the list to a
str
, you could use the join
method on str
.your_list = ['Hello', 'World'] the_seperator = " " my_new_str = the_seperator.join(your_list) print(my_new_str)Usually it's written more dense:
my_new_str = " ".join(your_list)If the list does not only contain
str
objects, you need to convert them.your_list = ['Hello', 'World', None, True, False, ...] the_seperator = " " to_str = map(str, your_list) # lazy evaluation # apply str(item) for each item in your_list my_new_str = the_seperator.join(to_str) print(my_new_str)
Unpacking arguments in function signature:
def greet(greeting, times, *names): for name in names: for _ in range(times): print(greeting.format(name)) greet("Hello {}.", 2, "zarize", "DeaD_EyE") # ^^^^^^^^^^^^^^^^^^^^^ <- *names
Unpacking keyword arguments in function signature:
def cook(**indigrents): for indigrent, how_often in indigrents.items(): print(indigrent.capitalize(), 'x', how_often) cook(beer=3, bannana=1) # ^^^^^^^^^^^^^^^^ <- **indigrents
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!