Programming from Scratch
Learn to code with Python, from your first variable to a real command-line tool.
11 projects, 275 hands-on levels, run in your browser.
Syllabus
- Foundations: code from zero: Never written code before? Start here. You will learn the absolute basics of Python, output, variables, types, decisions, loops, and functions, with simple everyday examples. By the end you are ready for Project 1.
- Foundations: The absolute basics: store values in variables, do arithmetic, work with text, convert between types, and print results. By the end you build a small receipt calculator.
- Control Flow: Teach your programs to decide and repeat. Booleans, if/elif/else, and/or/not, while and for loops, ending in a small board-game simulation.
- Functions: Package code into named, reusable tools. Parameters, return values, scope, defaults and keyword arguments, building up to a small Mad Libs story generator.
- Collections: Store and organise many values at once. Lists, dictionaries, sets and tuples, building up to a word-frequency report over real text.
- Strings and Text: Take text apart and put it back together. Slicing, the string methods, formatting and parsing, building up to a working Caesar cipher that encrypts and decrypts.
- Algorithmic Thinking: How computers solve problems efficiently. Recursion, linear and binary search, sorting from scratch, ending in a binary-search guessing-game solver.
- Objects: Bundle data and behaviour together with classes. Attributes, methods, state, and inheritance, building up to a tiny RPG where two characters duel automatically.
- Robust Programs: Write code that survives the real world. Catch and raise exceptions, read and write JSON, use the standard library, ending in an inventory loader that never crashes on bad data.
- Working with Data: Process collections with style. Comprehensions, filtering and mapping, lambdas and sorting keys, generators, building up to a sales-data report.
- Capstone: Build an App: Everything you have learned, in one project. Model tasks with dicts and lists, operate on them with functions and a class, parse text commands, and run them into a working command-line to-do app.
Key concepts
- Assignment: The operation of giving a name a value with = . Python evaluates the right side first, then binds the result to the name on the left, so x = x + 1 reads old x…
- Binary search: An algorithm that repeatedly halves a sorted search space. It is much faster than scanning for large inputs, but it only works when the data or answer predicat…
- Boolean: A truth value: either True or False . Booleans drive conditionals, loop stops, filters, validations, and comparisons such as age >= 18 .
- Class: A blueprint for creating objects that bundle data with behavior. Classes are useful when the same concept appears many times with the same fields and methods,…
- Comparison: An operation that asks a yes/no question about values, such as == , != , < , >= , or in . Comparisons produce booleans and are often combined with and ,…
- Conditional: An if / elif / else decision that runs code only when a condition is true. Conditionals let a program branch for cases like empty input, invalid data, or diffe…
- Data type: The kind of value an object holds, such as int , float , str , bool , list , or dict . Types decide which operations are valid: numbers can be added, strings c…
- Dictionary: A mutable mapping from keys to values, written like {"name": "Ada"} . Dictionaries are ideal for records, lookup tables, counters, grouped…
- Exception: A runtime problem represented as an object, such as ValueError , KeyError , or FileNotFoundError . try / except handles expected failure paths without crashing…
- Expression: Code that produces a value, such as 2 + 3 , name.upper() , or len(items) > 0 . Expressions can be stored in variables, passed to functions, or used inside c…
- File I/O: Reading from and writing to files. In Python, with open(...) as f: is the standard pattern because it closes the file reliably even if an error happens.
- Function: A named block of reusable code that can accept inputs and return an output. Functions make programs easier to test, reuse, and understand because each function…
- Iteration: Processing items one at a time from a sequence, file, range, dictionary, or generator. Good iteration avoids manual index bookkeeping unless the index itself m…
- JSON: A text format for structured data made from objects, arrays, strings, numbers, booleans, and nulls. Python dictionaries and lists map naturally to JSON when sa…
- List: An ordered, mutable collection. Lists are used for sequences of items you may append, remove, sort, slice, or update by index.
- Loop: A control structure that repeats work. Use for when iterating over known items, such as a list or range; use while when repetition depends on a condition that…
- Method: A function attached to an object and called with dot syntax, such as text.strip() or items.append(x) . Methods are how values expose behavior that belongs to t…
- Object: A value with type, identity, data, and behavior. In Python nearly everything is an object, including strings, lists, functions, classes, and exceptions.
- Parameter: A name in a function definition that receives an argument when the function is called. In def greet(name): , name is the parameter; in greet("Ada") ,…
- Range: A compact object that represents a sequence of integers, commonly used in for loops. range(5) yields 0 through 4 ; range(start, stop, step) controls the bounds…
- Recursion: A technique where a function solves a problem by calling itself on a smaller version of the same problem. It needs a base case to stop and is useful for trees,…
- Return value: The result a function sends back to its caller with return . Printing shows information to a person; returning gives a value back to the program so later code…
- Scope: The region of code where a name can be used. Local variables inside a function are separate from names outside it, which helps avoid accidental changes to dist…
- Set: An unordered collection of unique values. Sets make membership tests, duplicate removal, intersections, and differences concise and usually fast.
- Sorting: Rearranging data into order, such as ascending numbers or alphabetical names. Sorting makes searching, grouping, duplicate detection, and reports easier, but i…
- String: A sequence of text characters, written in quotes. Strings support indexing, slicing, searching, splitting, joining, formatting, and methods like .lower() and .…
- Tuple: An ordered, immutable collection, often used for fixed groups of values such as coordinates, return pairs, or dictionary keys. Because tuples do not change, th…
- Type conversion: Turning a value of one type into another, such as int("42") , str(99) , or list("abc") . Conversion is useful at input boundaries because u…
- Validation: Checking that input is acceptable before using it. Validation prevents confusing errors and makes programs safer by rejecting missing fields, wrong types, impo…
- Variable: A name bound to a value so the program can use it later. In Python, score = 10 creates or rebinds the name score ; the name is not the value itself, it points…