Bạn đang xem thử công khai
Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.
Review lesson. A summary of the functions part of Module 1, for quick reference and self-checking after unit 1.9.
def area(width, height=1, *extras, **options):
return width * height
| Concept | Meaning |
|---|---|
| Parameter | A name in the function definition (width, height) |
| Argument | A value passed at call time (area(3, 4)) |
| Default parameter | height=1 — used when no argument is passed |
*args | Collects extra positional arguments into a tuple |
**kwargs | Collects keyword arguments into a dict |
return a, b | Returns multiple values (actually a tuple) |
lambda x: x ** 2 | A one-line anonymous function, often used as key= for sorted |
global x inside the function (use sparingly; prefer passing values in and using return).