Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
- python syntax
- f-string
- enumerate
- dict get
- try except
Python Basics
Syntax survival kit: variables, loops, f-strings, and errors.
Commands
| Command | What it does |
|---|---|
python3 --version | Check the interpreter |
name = f"Hello, {user}" | f-string interpolation |
for i, item in enumerate(items): | Loop with index |
d.get("key", default) | Safe dict access |
try: ... except ValueError as e: | Handle one error type |
Example
users = ["ada", "grace"]
for i, u in enumerate(users, start=1):
print(f"{i}. {u.title()}")
FAQ
Python 2 vs 3?
Python 2 is end-of-life; all new code targets Python 3 (3.10+ for match statements).
How do I run a script file?
python3 script.py — or chmod +x with a #!/usr/bin/env python3 shebang.
Întrebări frecvente
Python 2 vs 3?
Python 2 is end-of-life; all new code targets Python 3 (3.10+ for match statements).
How do I run a script file?
python3 script.py — or chmod +x with a #!/usr/bin/env python3 shebang.
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 Strings
Slice, split, join, and format text efficiently.
Python Lists
Comprehensions, slicing, sorting, and friends for sequences.