Functions are created at run time


def and class are run-time Everything is runtime. Even compilation is runtime.

foo() will return a random value every time, but when bar is defined it freezes the specific value that foo returned when bar was created.


examples/advanced/runtime-def.py
import random

def foo():
    return random.random()


print(foo())
print(foo())

def bar(a, b = foo()):
   return [a, b]

print(bar(1))
print(bar(2))

0.0756804810689
0.350692064113
[1, 0.7401995987184571]
[2, 0.7401995987184571]