Python Essentials

Core syntax, data structures, and a uv-based modern dev workflow.

44 flashcards · select reveal or click a card to see details

basics beginner

Interpreter

Python code is run by an interpreter, which reads and executes your program.
basics beginner

Variables & Types

Python is dynamically typed: you don’t declare types, but they exist at runtime.
basics beginner

f-strings

The modern way to interpolate values into strings.
basics beginner

REPL

The REPL is an interactive Python session for trying code one line at a time.
basics beginner

Control Flow

Conditional execution with if/elif/else. Indentation defines blocks; there are no braces.
basics beginner

Loops

Iterate over sequences with for, repeat conditions with while.
basics beginner

Functions

Reusable blocks of logic with arguments and an optional return value.
data beginner

Types

A type describes what kind of value something is and what operations it supports.
basics beginner

None & Truthiness

Empty containers, 0, and None all evaluate as False in conditions.
data beginner

Strings

A string, or str, stores text.
data-structures beginner

Lists

Ordered, mutable sequence: your default choice for collections.
data-structures beginner

Dictionaries

Key-value mapping with O(1) lookup.
data-structures beginner

Tuples & Sets

Tuples are immutable lists; sets are unordered collections of unique items.
data-structures beginner

Comprehensions

Concise way to build a list, dict, or set from an iterable.
data-structures beginner

Iterating Patterns

enumerate, zip, and dict.items() cover most iteration needs.
data beginner

Sets

A set stores unique values with no guaranteed order.
modules-env beginner

Imports

Bring code from other files or installed packages into your script.
modules-env beginner

uv Project Setup

uv handles your project’s virtual environment, dependencies, lockfile, and Python version automatically.
modules-env beginner

uv run

Run a Python command inside the project’s environment without activating it.
modules-env beginner

Python Versions

uv installs and switches between Python versions per project.
functions beginner

return vs print

return sends a value back to the caller; print displays text in the terminal.
modules-env beginner

pyproject.toml

The project config file: declares dependencies, Python version, scripts, and tool settings.
functions intermediate

Scope

Scope determines where a name can be used.
modules-env beginner

uv tool (uvx)

Install Python CLIs globally without polluting any project’s environment.
organization intermediate

__name__ guard

The if __name__ == "__main__" guard runs code only when a file is executed directly.
modules-env beginner

Standard Library

Modules you’ll reach for constantly: pathlib, json, os, datetime, re.
utilities beginner

File I/O

Read and write files with the with statement to auto-close.
tooling beginner

Virtual environments

A virtual environment isolates a project’s Python packages from the rest of your machine.
utilities beginner

Error Handling

try/except catches exceptions; handle specific ones, not bare except.
tooling beginner

pip

pip installs Python packages from package indexes like PyPI.
utilities beginner

pathlib

Object-oriented file paths: the modern replacement for os.path.
utilities beginner

subprocess

Run shell commands from Python and capture output.
utilities beginner

argparse

Build CLI tools with parsed flags and positional arguments.
files intermediate

Context managers

A context manager sets something up and reliably cleans it up afterward.
workflows intermediate

Set Up a New Project

Bootstrap a new Python project with uv. One tool handles the venv, dependencies, Python version, and lockfile.
workflows intermediate

Run Scripts & Modules

Two main ways to run Python code with uv, plus the __main__ guard for files meant to be both run and imported.
data beginner

None

None represents the absence of a value.
workflows intermediate

Read JSON Config

A common pattern: parse a JSON config file with sensible error handling and fallback to defaults.
object-oriented intermediate

Classes and objects

A class defines a type of object with data and behavior.
workflows intermediate

Debug

Three escalating tools: print, breakpoint, and logging. Each is appropriate at different times.
object-oriented intermediate

self

self refers to the current object inside a class method.
workflows intermediate

Test with pytest

The standard Python testing framework. Tests are functions starting with test_ in files named test_*.py.
patterns intermediate

Generators

A generator produces values lazily, one at a time, instead of building a whole list.
tooling intermediate

Type hints

Type hints document expected value types and help tools catch mistakes.