1# testing default args to a function 2 3def fun1(val=5): 4 print(val) 5 6fun1() 7fun1(10) 8 9def fun2(p1, p2=100, p3="foo"): 10 print(p1, p2, p3) 11 12fun2(1) 13fun2(1, None) 14fun2(0, "bar", 200) 15try: 16 fun2() 17except TypeError: 18 print("TypeError") 19try: 20 fun2(1, 2, 3, 4) 21except TypeError: 22 print("TypeError") 23 24# lambda as default arg (exposes nested behaviour in compiler) 25def f(x=lambda:1): 26 return x() 27print(f()) 28print(f(f)) 29print(f(lambda:2)) 30