>>> def f(x): return x + 2 ... >>> f(5) 7 >>> f = 14 >>> # function names are variable names >>> >>> 5 5 >>> (lambda x: 3*x + 1)(5) 16 >>> (lambda : print("cows"))() cows >>> quack = lambda x, y: x + y >>> quack(4,5) 9 python table_of_values.py 5125 MAC:Thu Mar 03:10:39:0303> !vi MAC:Thu Mar 03:10:45:0303> !p python table_of_values.py
xf(x)
464
6216
7343
28
88681472
11
-4-64
>>> x = ["cat", "dog", "elephant"] >>> for k, item in enumerate(x): ... print(f"x[{k}] = {x[k]}") ... x[0] = cat x[1] = dog x[2] = elephant >>> for k, item in enumerate(x, 50): ... print(k, item) ... 50 cat 51 dog 52 elephant >>> for k in enumerate("caterwaul", 10): ... print(k[0], k[1]) ... 10 c 11 a 12 t 13 e 14 r 15 w 16 a 17 u 18 l >>> for k, item in enumerate("caterwaul", 10): ... print(k, item) ... 10 c 11 a 12 t 13 e 14 r 15 w 16 a 17 u 18 l >>> >>>