hayaliv / Hi! Python
Hi! Python
Python for AI, in plain words. Fifteen short lessons with everyday analogies, a worked example, predict-the-output questions and a small exercise. Every statement about Python is backed by a word-for-word quote from the official Python 3.12 documentation, or by code that was actually run.
Open the interactive desktop (step-by-step code view)
Level 0: Python core
This level covers the Python you need before touching any model code: values, text, collections, loops, functions and comprehensions. Each lesson uses small examples from a cold-email reply classifier.
- Values, variables and types — Every value has a type, and a name refers to a value.
- Strings and f-strings — Strings are text you can index, slice, clean with methods, and fill in with f-strings.
- Lists, tuples, dicts and sets — Lists change, tuples do not, dicts look things up by key, and sets keep unique items.
- Control flow — if chooses a path, for and while repeat work, and break and continue steer a loop.
- Functions — A function packages steps under a name, takes parameters, and hands back a value.
- Comprehensions — A comprehension builds a list, dict or set from another collection in one short line.
Level 1: Files and data
Real projects start with data in files. In this level you read text, JSON, JSON lines, CSV, and clean text with simple patterns.
- Text and the `with` statement — Read text one line at a time, and let
withclose the file for you. - JSON — Turn Python data into JSON text and back with json.dumps and json.loads.
- JSONL-style records: one JSON object per line — Store one JSON object per line, then read it back line by line and report bad lines by number.
- CSV — Read and write comma-separated tables with csv.reader, DictReader and DictWriter.
- Regular expressions, the basics — Find, extract and replace text patterns with re.search, re.findall and re.sub.
Level 2: Level 2: Writing reliable code
Real data is messy and mistakes are easy to make. These four tools help you write records clearly, say what you expect, handle errors on purpose, and stream data one piece at a time.
- Dataclasses — @dataclass writes __init__, __repr__ and __eq__ for you, so a record like Example(input, label) takes a few lines.
- Type hints — Type hints label what a variable or function expects. Python does not enforce them, but tools such as type checkers can read them.
- Exceptions — try/except lets a program handle a known error on purpose. Catch specific exceptions and raise your own when data is bad.
- Generators and lazy iteration — A generator function uses yield to hand back one item at a time, so you can stream records without building a full list.