Skip to content

Instantly share code, notes, and snippets.

@leveled
Created February 22, 2021 00:46
Show Gist options
  • Save leveled/bc52f68bfab6e81473e8d9f84bb50ef1 to your computer and use it in GitHub Desktop.
Save leveled/bc52f68bfab6e81473e8d9f84bb50ef1 to your computer and use it in GitHub Desktop.
Capture an unlimited number of positional arguments given to a function in Python
from random import randint
def roll(*dice):
return sum(randint(1, die) for die in dice)
>>> roll(20)
18
>>> roll(6, 6)
9
>>> roll(6, 6, 6)
8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment