Lecture 2 · Functions
-
from operator import add, mul
- This binds a function to a name.
- If you then write add = 100, calling add(1, 10) raises an error instead of calling the function.
- To use it again, bind the function to the name again, or first save it with f = add and call f afterward!

-
A call expression evaluates its arguments before calling the function.
- See the later note Lec 4 - High Order Functions for the discussion of if/else.
- ⚠️ Python evaluates the right-hand side of an assignment before assigning the result to the left-hand side.
-
funtions
- pure: just return values
- non-pure: have side effects
-
print
- print returns None

- print returns None
English translation · Read Chinese original
