def print_twice(value): print(value) print(value) print_twice("Hello there")
print
input
def square(n): return n*n print(square(2)) print(square(7))
We can reimplement min ourselves
min
def min(a, b): if a < b: return a else: return b
Functions may call other functions
def square(n): return n*n def cube(n): return n * square(n) print(cube(2))
def repeat(task, num_times): if num_times > 0: task() repeat(task, num_times - 1) def greet(): print("Hello!") repeat(greet, 3)
def fib(n): if n <= 1: return n return fib(n-2) + fib(n - 1) print(fib(20))