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.
- Modularization
- Functions
- Writing functions: is_even()
- Writing functions: Syntax summary
- s_odd()
- Example: dice_roll()
- Default Arguments
- Playing Card Functions 1
- Reusing Functions
- Modules
- Documenting modules and functions
- Summary: Module Layout
- Example: Playing Card Functions 2
- Refining import
- Scope
- The Perils of Mutability*
- Reference Semantics
- Using versus changing a list
- Copying a list
- List comprehensions
- What are these pyc files?
- Finding the Standard Library Modules
- Assignment 6