Python
Overview
Python is a high-level, general-purpose programming language emphasizing readability and a large standard library ("batteries included"). It is dynamically typed, garbage-collected, and supports procedural, object-oriented, and functional styles. CPython is the reference implementation. Read this for core syntax, packaging/virtual environments, and standard-library usage.
Official sources
Install / setup
Download and run the installer for your platform from https://www.python.org/downloads/. Verify the install:
python3 --version
Core concepts
- Indentation-defined blocks: whitespace (not braces) delimits code blocks; consistent indentation is syntactically required.
- Dynamic typing with strong typing: names are bound to objects of any type at runtime, but Python does not silently coerce unrelated types.
- Everything is an object: functions, classes, and modules are first-class objects; duck typing drives polymorphism.
- The standard library: a broad set of built-in modules (os, json, pathlib, datetime, itertools, etc.) cover common tasks without third-party packages.
- Virtual environments:
venv isolates per-project dependencies from the system interpreter.
- Iterators, generators, and comprehensions: lazy iteration via
__iter__/yield; concise list/dict/set comprehensions.
- Exceptions: errors are raised and caught with
try/except/finally; use specific exception types.
Best practices
- Follow PEP 8, the official style guide, for layout, naming, and formatting.
- Use a virtual environment (
python3 -m venv .venv) per project so dependencies don't collide with the system Python.
- Prefer context managers (
with open(...) as f:) so resources are released deterministically.
- Catch specific exceptions rather than bare
except:; let unexpected errors surface.
Common pitfalls
- Mutable default arguments (
def f(x=[]):) → the default is created once and shared across calls; use None and create inside the function.
- Mixing tabs and spaces for indentation → causes
TabError/inconsistent blocks; use spaces consistently (PEP 8 recommends 4 spaces).
- Relying on dict/iteration order assumptions across versions → insertion order is guaranteed for dicts in modern CPython, but don't depend on set ordering.
- Installing packages into the system interpreter globally → use a virtual environment to avoid conflicts.
Examples
from pathlib import Path
def read_lines(path: str) -> list[str]:
with open(path, encoding="utf-8") as f:
return [line.rstrip("\n") for line in f]
for line in read_lines("data.txt"):
print(line)
Further reading
Related skills
- (sibling language skills under ../)
1---2name: python3description: Batteries-included, general-purpose dynamic language; consult for core syntax, the standard library, and environments.4domain: language5category: language6tags: [python, cpython, scripting, stdlib, venv]7official_sources:8 - https://docs.python.org/3/9 - https://github.com/python/cpython10 - https://www.python.org/downloads/11verified: 2026-06-1612metadata:13 source: https://skillmd.com/skills/gabriel7silva/python14---1516# Python1718## Overview19Python is a high-level, general-purpose programming language emphasizing readability and a large standard library ("batteries included"). It is dynamically typed, garbage-collected, and supports procedural, object-oriented, and functional styles. CPython is the reference implementation. Read this for core syntax, packaging/virtual environments, and standard-library usage.2021## Official sources22- Docs: https://docs.python.org/3/23- Repo (CPython reference implementation): https://github.com/python/cpython24- Install / download: https://www.python.org/downloads/2526## Install / setup27Download and run the installer for your platform from https://www.python.org/downloads/. Verify the install:28```bash29python3 --version30```3132## Core concepts33- Indentation-defined blocks: whitespace (not braces) delimits code blocks; consistent indentation is syntactically required.34- Dynamic typing with strong typing: names are bound to objects of any type at runtime, but Python does not silently coerce unrelated types.35- Everything is an object: functions, classes, and modules are first-class objects; duck typing drives polymorphism.36- The standard library: a broad set of built-in modules (os, json, pathlib, datetime, itertools, etc.) cover common tasks without third-party packages.37- Virtual environments: `venv` isolates per-project dependencies from the system interpreter.38- Iterators, generators, and comprehensions: lazy iteration via `__iter__`/`yield`; concise list/dict/set comprehensions.39- Exceptions: errors are raised and caught with `try`/`except`/`finally`; use specific exception types.4041## Best practices42- Follow PEP 8, the official style guide, for layout, naming, and formatting.43- Use a virtual environment (`python3 -m venv .venv`) per project so dependencies don't collide with the system Python.44- Prefer context managers (`with open(...) as f:`) so resources are released deterministically.45- Catch specific exceptions rather than bare `except:`; let unexpected errors surface.4647## Common pitfalls48- Mutable default arguments (`def f(x=[]):`) → the default is created once and shared across calls; use `None` and create inside the function.49- Mixing tabs and spaces for indentation → causes `TabError`/inconsistent blocks; use spaces consistently (PEP 8 recommends 4 spaces).50- Relying on dict/iteration order assumptions across versions → insertion order is guaranteed for dicts in modern CPython, but don't depend on set ordering.51- Installing packages into the system interpreter globally → use a virtual environment to avoid conflicts.5253## Examples54```python55from pathlib import Path5657def read_lines(path: str) -> list[str]:58 with open(path, encoding="utf-8") as f:59 return [line.rstrip("\n") for line in f]6061for line in read_lines("data.txt"):62 print(line)63```6465## Further reading66- The Python Tutorial: https://docs.python.org/3/tutorial/67- PEP 8 style guide: https://peps.python.org/pep-0008/6869## Related skills70- (sibling language skills under ../)