Notable Features of Python

by V James Powell  (vpowell at gmail dot com)

Downloads

About

Covers some of the more notable features of Python: functional programming basics, as well as decorators, iterators and generators, and context managers. Discussion of where and why these features are useful, motivated by simple examples of real-world uses. Focuses on Python 2.7< but includes brief mention of relevant changes in Python 3000.

  1. functions are "first-class citizens" what does this mean? how does this allow us to write better code? what "patterns" does this eliminate? what common patterns/idioms are there?
  2. functions, objects, and callables what are functions under the hood? what is a callable? what are the various ad hoc protocols?
  3. function decorators & class decorators where might these be useful? where do these show up in the standard library? what is a function decorator? what is a decorator-generating function? what's going on under the hood?
  4. iterators how does a for-loop work? how do iterators work on standard data types? how do I define my own iterators? how can I define my own tuple unpacking?
  5. generators what is a generator? how do generators relate to comprehensions? what other things can be done with `yield` (e.g., coroutines)?
  6. context managers where are these useful? what commonly used context managers are available? how do I write one myself (using a class, using a generator?)