Python for college and professionals

Intermediate — data, modules, errors, objects

Original RSIL middle course covering the rest of the language-tutorial + types-course union: tuples, files, sets, list edits, looping techniques, comprehensions-as-loops, docs, scopes, nested functions, argument traps, recursion/lambda/map, modules and packages, formatted I/O, exceptions and cleanup, classes, inheritance and tests.

Your progress (this browser)

0%

0 of 21 lessons complete

Level exam
  1. Lesson 1 · 48 min

    Tuples — a shape that should not grow

    Gate latitude/longitude is two numbers, not a tray that sprouted a note. On a laptop that stiffness is a tuple. Here it is a two-field recor

    Start
  2. Lesson 2 · 52 min

    Files: open, read, write, close

    A CSV on disk is text until you parse it. open, read, write, close (or with) are the edge. In memory the honest twin is a list of labelled r

    Start
  3. Lesson 3 · 48 min

    Sets — unique, then compare

    Enrolled minus seated is a difference of two unique collections. Duplicates in a roll list are a bug. Union and intersection are the same id

    Start
  4. Lesson 4 · 48 min

    del and editing a list in place

    The third UPI row was a duplicate. You may replace it by index or drop it. del is the laptop spelling; here you rebuild keepers so the sourc

    Start
  5. Lesson 5 · 52 min

    Looping techniques: index, zip, dict keys

    Sometimes you need the seat number and the student. Sometimes two lists must walk in lockstep (marks and rolls). enumerate and zip are the l

    Start
  6. Lesson 6 · 48 min

    Membership, nested tests, comparing sequences

    is this roll in the seated list? Nested ifs are and/or when the sandbox has no and. Two lists compare in full Python by the first difference

    Start
  7. Lesson 7 · 50 min

    Comprehensions — the short spelling of a filter loop

    Keep heat days; double a list of quantities. The long form is a new list plus append. The one-liner on a laptop is a comprehension. Debug th

    Start
  8. Lesson 8 · 46 min

    Comments, dir, help and docstrings

    dir(x) lists names. help(x) prints docs. A docstring is the spec on the function. Comments explain why, not what the names already say.

    Start
  9. Lesson 9 · 52 min

    Scopes: locals, globals, LEGB

    A parameter named rate does not rewrite CONFIG unless you pass CONFIG. Locals die at return. global is a last resort. LEGB is the search ord

    Start
  10. Lesson 10 · 48 min

    Nested helpers and remembered values

    A tiny helper that only one function needs can live inside it. A nested function that still sees an outer name after the outer call returns

    Start
  11. Lesson 11 · 52 min

    Argument traps: keywords, mutables, extras

    A default list that is created once will keep growing across calls — a famous trap. Keyword calls document order. *args/**kwargs collect ext

    Start
  12. Lesson 12 · 52 min

    Recursion, tiny functions, map and filter

    A loop is usually clearer than recursion for campus totals. lambda is a nameless one-line def. map and filter are loops with extra syntax —

    Start
  13. Lesson 13 · 52 min

    Modules: import, from, search path

    A module is a file of names. import loads it once. from copies names. The search path is why ‘it works on my USB’ fails on the lab PC. reloa

    Start
  14. Lesson 14 · 50 min

    Packages, __init__, relative imports

    A folder of modules with a public name is a package. __init__ runs when the package is imported. Relative imports (from . import fees) are f

    Start
  15. Lesson 15 · 50 min

    The program door, hiding names, import as

    Importing fees.py must not print a receipt. if __name__ == "__main__" is the door. _name and __all__ tell from * what to copy. import pandas

    Start
  16. Lesson 16 · 48 min

    Formatted output people can audit

    Units on the label; one number in the function. format(), templates and column widths live on a laptop. The kiosk and the CSV must not inven

    Start
  17. Lesson 17 · 54 min

    Exceptions: try, except, raise

    Syntax errors never run. Runtime errors can be caught. raise is how you refuse garbage with a name. User-defined errors are classes on a lap

    Start
  18. Lesson 18 · 50 min

    finally, with, assert

    finally always runs — close the file. with open(...) as f does that for you. assert is a check for developers, not a user-facing KYC message

    Start
  19. Lesson 19 · 54 min

    Classes, instances and methods

    A class is a named record plus behaviour. __init__ fills fields. A method is a function that belongs with the data. Fifty motors should not

    Start
  20. Lesson 20 · 54 min

    Inheritance, composition and _privacy

    Share a reporter; put the difference in a field or a subtype. Has-a (a lab has a sensor) is often simpler than is-a. _name is a convention:

    Start
  21. Lesson 21 · 50 min

    Tests as an executable spec

    PASS/FAIL next to the wall-notice numbers. unittest, pytest and doctest are laptop runners. A green bar only proves the cases you wrote.

    Start