AFAIK, Python evaluates the defaults of a function only once, at declaration time. So calling the following function printRandom
import random
def printRandom(randomNumber = random.randint(0, 10)):
print randomNumber
will print the same number each time called without arguments. Is there a way to force reevaluation of the default randomNumber
at each function call without doing it manually? Below is what I mean by "manually":
import random
def printRandom(randomNumber):
if not randomNumber:
randomNumber = random.randint(0, 10)
print randomNumber