Skip to content

Python

Standard Library

Packages

Interpreter

  • You can configure your IDE to use a python interpreter (the python binary) with a specific version
  • The python binary can also be picked from your chosen virtual environment
  • On vscode, Python: Select Interpreter

Virtual Environment

  • Each virtual environment is created based on a python interpreter (version)
  • A virtual environment contains all libraries and binaries isolated from the operating system
  • Even the python binary is isolated (although symlinked to the system python binary)
  • Options
  • venv: the native virtual environment solution
  • virtualenv: 3rd party
  • pipenv: 3rd party, more recent
python -m venv .venv
source ./.venv/bin/activate # bash
source ./.venv/bin/activate.fish # fish
echo $VIRTUAL_ENV
echo $PATH

Language Server

  • Jedi: Community-driven
  • Pylance: Developed by Microsoft

  • With homebrew, source files are installed at /opt/homebrew/Cellar/[email protected]/3.12.1_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12

Linter & Formatter

Expression vs. Statement

  • Statement: any unit of code
  • Expression: special statement that evaluates to some value
# Expression
1 + 2 # evaluates to 3
"a" if 1 != 1 else "b" # evaluates to "a"

# Statement (assignment)
foo = 1 + 2 # doesn't return any value