Python Functions
Args, kwargs, lambdas, and signatures that document themselves.
- python functions
- args kwargs
- lambda
- lru_cache
- type hints
Python Functions
Args, kwargs, lambdas, and signatures that document themselves.
Commands
| Command | What it does |
|---|---|
def f(name, *, verbose=False): | Keyword-only arg after * |
def f(*args, **kwargs): | Catch-all parameters |
lambda x: x * 2 | Tiny anonymous function |
functools.lru_cache | Memoize pure functions |
def f(path: str) -> int: | Type-annotated signature |
Example
from functools import lru_cache
@lru_cache(maxsize=1024)
def fib(n: int) -> int:
return n if n < 2 else fib(n-1) + fib(n-2)
FAQ
**When is *args/kwargs right?
Decorators and pass-through wrappers; concrete signatures are better for public APIs.
Do type hints run at runtime?
No — they are metadata for mypy/IDEs; use pydantic or asserts for runtime validation.
자주 묻는 질문
When is *args/**kwargs right?
Decorators and pass-through wrappers; concrete signatures are better for public APIs.
Do type hints run at runtime?
No — they are metadata for mypy/IDEs; use pydantic or asserts for runtime validation.
Python
Python Venv and Environments
Isolate dependencies per project with venv and pinned requirements.
Python Pip Essentials
Install, upgrade, and audit packages with pip like a pro.
Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
Python Strings
Slice, split, join, and format text efficiently.