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

CommandWhat it does
python3 --versionCheck 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.

자주 묻는 질문

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