Highly Recommended Viewing
- Kris Joran's Intro to Python Functions
- Function Call Syntax
- Function Call Semantics
- Stack Diagram Practice
What's this :int thing, or "Are you my type?"
Arguments vs. Parameters
---------------------- ----------------
Global frame HEAP
hypot -------------------------------> CODE
MORTUUS
----------------------
print s -> "5"
MORTUUS
----------------------
hypot x -< 4
y -< 3 MORTUUS
ret 5
---------------------
output:
$ python argsVsParams.py
5
---------------------
Python is a pass by value language What gets passed to a function parameter? A copy of the memory address of the object being returned.
Python variables only store MEMORY ADDRESSES on the heap.
FAncy Arugments
- positional arguments. These come first.
- starguments. You can have one.
- keyword arguments. These come last. They must be initlaized.
| x | f(x) |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 8 |
| 3 | 27 |
| 4 | 64 |
| 5 | 125 |
| 6 | 216 |
| 7 | 343 |
| 8 | 512 |
| 9 | 729 |