*args
say it: “STAR ARGZ” /ˈstɑr ˈɑrɡz/
Lets a function accept any number of positional arguments, collected as a tuple.
What does *args do?
*args lets a function accept any number of positional arguments. Inside the function they arrive together as a tuple.
def total_price(*prices):
return sum(prices)
print(total_price(3, 5, 12)) # 20
Level: Apprentice · More Python terms at this level
Updated