Skip to content

Introduction to Programming in Python

College12 units and 37 lessons. Helio talks each one through and draws each step on a board.

Units

  1. Values, types and expressions

    3 lessons
    1. Values, types and expressionsEvaluate a Python arithmetic expression, including //, % and **, and say its value and its type.
    2. Variables and assignmentTrace a sequence of assignments in a table of names and values, including reassignment, augmented assignment and a swap of two names.
    3. Input, output and type conversionRead values typed by the user with input(), convert them with int() and float(), print the result with an f-string, and say which error a mistake gives.
  2. Booleans and conditionals

    2 lessons
    1. Booleans and comparisonsEvaluate a condition built from comparisons and and, or, not, and write one for a range or for the leap-year rule.
    2. if, elif and elseWrite and trace an if, elif and else chain whose conditions are ordered so that each input reaches the one block that is meant for it.
  3. Loops

    4 lessons
    1. while loopsWrite and trace a while loop, with a counter or a sentinel, and say how many times its body runs.
    2. for loops and rangeTrace a for loop over range(start, stop, step) and over a string, giving the values its loop variable takes, and choose for or while for a task.
    3. Loop patterns: accumulate, count, searchWrite and trace the accumulator, counter, running-maximum and search-with-break loop patterns over a list of numbers.
    4. Nested loopsTrace nested for loops, count how many times the inner body runs, and write them to print a multiplication table and a triangle of stars.
  4. Functions

    4 lessons
    1. Defining and calling functionsDefine a function with parameters and return, call it with arguments, and tell what it returns from what it prints, including the None of a function without return.
    2. Scope and the call stackTrace a program with one frame for each function call, say which names each call can read, and explain why a local variable is gone after its function returns.
    3. Default and keyword arguments and docstringsWrite functions with default parameter values, call them with positional and keyword arguments, and document them with a docstring that says what goes in and what comes out.
    4. Designing with functionsBreak a task into small functions that each do one thing, write them top-down from a main function, and test each one on its own with chosen inputs.
  5. Strings

    3 lessons
    1. String indexing and slicingRead characters with positive and negative indexes, take slices s[a:b] and s[a:b:c], and predict each from a drawn index row.
    2. String methods and immutabilityClean, search, split and join text with string methods, and show that each returns a new string because strings cannot change.
    3. Processing text with loopsLoop over a string's characters to count vowels, reverse a word and test a palindrome, building results with a counter or a string accumulator.
  6. Lists and tuples

    6 lessons
    1. Lists: indexing and mutationCreate a list, read and change its items by index, and use append, insert, pop and remove, saying what the list is after each call.
    2. Traversing listsWalk through a list by value and by index to sum, find the largest and its position, change items in place and build a filtered list, and say which walk each job needs.
    3. Aliasing and mutabilityDraw names as arrows to list objects, say when two names share one list, copy a list with a slice or list(), and say what a function that changes its list argument does to the caller.
    4. Tuples and unpackingUse a tuple as a fixed record, unpack it into names in an assignment and in a for loop with enumerate and zip, and return two values from a function.
    5. Nested lists and gridsRead and visit the cells of a grid held as a list of lists, and build one whose rows are separate lists.
    6. List comprehensionsRead and write a list comprehension with an optional condition, and rewrite a loop that builds or filters a list as one.
  7. Dictionaries and sets

    3 lessons
    1. DictionariesStore, look up, add, update and loop over key-value pairs in a dictionary, count words with one, and say which keys a dictionary accepts.
    2. SetsBuild a set to drop duplicates and test membership, combine two sets with union, intersection and difference, and say why a set membership test is fast.
    3. Nested data: lists of dictionariesRead and summarise a list of dictionaries used as records, choosing a list, tuple, set or dictionary for each job.
  8. Files and exceptions

    3 lessons
    1. Reading and writing filesRead a text file line by line into values, and write results to a new file in the mode that keeps the data.
    2. ExceptionsCatch ValueError and FileNotFoundError with try and except so a program recovers from bad input, and raise an exception for input a function must refuse.
    3. Processing CSV dataRead a CSV file with the csv module and total and average its converted numbers by group with a dictionary.
  9. Classes and objects

    3 lessons
    1. Classes, objects and __init__Write a class with __init__ and attributes, make objects from it, and say that each object keeps its own attributes while two names can point to one object.
    2. Methods, self and __str__Write methods that read and change an object's attributes through self, and give the class a __str__ that returns the text print shows.
    3. InheritanceWrite a subclass that inherits from BankAccount, calls the parent with super(), overrides a method, and say which method runs for each object.
  10. Recursion

    2 lessons
    1. Recursion: base case and recursive caseWrite recursive functions with a base case and a smaller recursive call, and trace them on the call stack.
    2. Recursion on strings and listsWrite recursive functions on strings and lists that handle the first item and recurse on the rest, with the empty string or list as the base case.
  11. Searching and sorting

    2 lessons
    1. Linear and binary searchWrite linear search and binary search, tracing binary search's low, mid and high on a sorted list and counting comparisons, up to n against about log2 n.
    2. Selection sort and insertion sortTrace and write selection sort and insertion sort pass by pass, and count their comparisons as about n²/2 in the worst case.
  12. Testing and debugging

    2 lessons
    1. Testing with assert and test casesWrite assert test cases for ordinary, edge and error inputs, and find the bugs that only an edge case reveals.
    2. DebuggingFind and fix bugs by reading a traceback from the bottom up, tracing code with prints and a table of variables, and correcting off-by-one and wrong-condition mistakes.

A tutor you can talk to

30 minutes every month. No card.