Star Args in Python
Level 383 keystrokes
This defines a function with *args to accept any number of positional arguments as a tuple.
Python code
# *args collects any number of positional arguments into a tuple1def sum_all(*args): # sum() adds up every value in the tuple2 return sum(args)3 # Inside the function, args is (1, 2, 3, 4, 5)4result = sum_all(1, 2, 3, 4, 5)# Prints 155print(result)Output
15
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 4(× 4)× 4_× 2:× 1*× 1=× 1