This repository contains a collection of Python learning exercises grouped by topic. Each folder is a small, self-contained set of exercises that focus on a single concept (type annotations, async programming, async comprehensions, testing, etc.). These exercises are intended for practice and learning, and most files can be executed directly with the Python interpreter.
This README provides a quick overview of the project structure, setup steps for a Linux (zsh) environment, and commands to run the examples and tests.
Table of contents
- Project layout
- Prerequisites
- Setup (venv & dependencies)
- How to run examples
- Running tests
- Notes and tips
Project layout
0x00-python_variable_annotations/— Small functions and scripts that exercise Python type annotations, typed function signatures, and static typing patterns (e.g.,add,concat,type_checking).0x01-python_async_function/— Examples that show basic async function syntax, running concurrent coroutines, measuring runtime and creating tasks.0x02-python_async_comprehension/— Exercises covering async generators and async comprehensions with simple measurement utilities.0x03-Unittests_and_integration_tests/— Exampleunittest-based client code, fixtures and tests demonstrating unit and integration testing patterns. Containstest_client.py,test_utils.pyand supporting modules.
Prerequisites
- Python 3.8+ (3.10/3.11 recommended)
- pip
- Optional: virtualenv or use
python3 -m venv
Setup (Linux / zsh)
Open a terminal and run:
# create and activate a virtual environment in the project root
python3 -m venv .venv
source .venv/bin/activate
# upgrade pip
pip install --upgrade pipDependencies
Most exercises are self-contained and don't require third-party packages. For testing and convenience you may want to install pytest or other test tools, but the provided tests use Python's standard unittest module and will run without extra dependencies.
Optional (recommended for richer test output):
pip install pytest pytest-covHow to run examples
Each exercise file is a small script or module. You can run them directly with the interpreter. From the repository root:
# run a simple example from the variable annotations exercises
python3 0x00-python_variable_annotations/0-add.py
# run an async example (these are simple scripts demonstrating usage patterns)
python3 0x01-python_async_function/0-basic_async_syntax.py
# run an async comprehension example
python3 0x02-python_async_comprehension/1-async_comprehension.pyRunning tests (unittest)
The 0x03-Unittests_and_integration_tests/ folder contains unittest-based tests. Run them with Python's test discovery or with pytest if installed.
Using Python's unittest discovery:
# from repository root
python3 -m unittest discover -v 0x03-Unittests_and_integration_testsUsing pytest (if installed):
pytest -q 0x03-Unittests_and_integration_testsFolder notes and highlights
0x00-python_variable_annotations/— Good place to practice adding static types and learning how to write function signatures that help static type checkers (e.g.,mypy). Files such as100-safe_first_element.pyand101-safely_get_value.pyillustrate safe handling of values and typing for optional results.0x01-python_async_function/— Shows coroutine creation, awaiting, running multiple coroutines concurrently and measuring runtime. Useful for learningasynciobasics.0x02-python_async_comprehension/— Demonstrates how to use async generators and comprehensions to process asynchronous streams of data.0x03-Unittests_and_integration_tests/— Example fixtures and tests that demonstrate how to structure unit and integration tests. Theclient.pyandutils.pymodules are the code under test;test_client.pyandtest_utils.pyare test modules.
Tips and recommended next steps
- If you want static type checking, install
mypyand run it against the0x00-...folder:
pip install mypy
mypy 0x00-python_variable_annotations- To experiment with asynchronous code, open the examples and add
print()statements or small modifications — run them interactively in the venv. - Consider adding a
requirements.txtif you adopt third-party packages for testing or linting.
Contributing
If you want to add exercises or improve documentation, fork the repository and open a pull request with your changes.
- Ahonakpon Guy Gbaguidi - [email protected]
Using Python3 to develop a app backend ALX Software Engineering