Introduction: Coding in chunks đŸ§±

How time flies — at the end of this module you'll be halfway through the course material!

Brian Kernighan says that “Controlling complexity is the essence of computer programming” and this week we start to look at language features that allow us to control complexity.

Hopefully you have noticed that your longer programs, for example the password checking program, are made up of "chunks" of code that almost stand on their own. Programming languages give you a way to isolate these chunks so you can focus on writing them one at a time (reducing the complexity of what you have to think about, win) and then give them names so you can reuse them (reducing the complexity of writing future programs, win-win!). Sometimes we reuse one chunk multiple times in the same program, for example we've written several programs that call random.randint() more than once, and sometimes we reuse chunks of code in multiple programs. Python provides three ways of chunking — functions, classes and modules — and this week we'll cover functions and modules, and develop some “chunks” for working with playing cards.

  1. Modularization
  2. Functions
  3. Writing functions: is_even()
  4. Writing functions: Syntax summary
  5. s_odd()
  6. Example: dice_roll()
  7. Default Arguments
  8. Playing Card Functions 1
  9. Reusing Functions
  10. Modules
  11. Documenting modules and functions
  12. Summary: Module Layout
  13. Example: Playing Card Functions 2
  14. Refining import
  15. Scope
  16. The Perils of Mutability*
  17. Reference Semantics
  18. Using versus changing a list
  19. Copying a list
  20. List comprehensions
  21. What are these pyc files?
  22. Finding the Standard Library Modules
  23. Assignment 6