Python Constructs
This page will be continually updated with a list of Python keywords and
constructs that we've learned in class to date. Python has many capabilities,
functions, and data structures built in to the language and the standard
libraries. Part of the objective of this class is to teach you the basic
software tools of programming, so you are asked to limit your Python
programs to the constructs
that we've learned in class to date and not to use a prepackaged Python
function that does it all for you.
If there's a function not here that you want to use, just ask me.
Updated 3 Nov 2006
- bool, int, float, str, tuple
- operators: +, /, *
- print, type()
- and, or, not
- import, everything in standard math library
- triple-quoted strings
- input(), raw_input()
- sys.stdout.write()
- comments, docstrings
- operators: //, **, %, ==, !=, <>, <, >, <=, >=, is, is
not
- shortcut semantics
- int(), float(), bool(), str()
- print format strings (%d, %f, %s, etc.)
- if, if/else, if/elif/else
- while, break, continue, else
- abs
- +=, -=, *=, /=, etc.
- string.capitalize()
- string concatenation (+), string repetition (*)
- for, range
- procedures/functions (def), return
- string.upper(), .lower()
- chr(), ord(), len()
- indexing into strings: myString[i]
- lists: indexing (list[i]), slices (list[:]), del, in,
concat (+) and repeat (*)
- files: open(), close(), read(), readline(), readlines(),
write(), flush(), seek(), tell()
- sys.stdin, sys.stdout, sys.stderr, os.chdir
- string.isalnum(), .isalpha(), .isdigit(), .islower(), .isupper(),
.isspace()
- hex(), oct(), 0x..., 0.... (hex/oct literals)
- bitwise operators: &, |, ^, <<, >>
- random.random(), random.seed()
- time.time()
- built-in set() type; operations on set
- defining a class, instantiating, methods
- id, copy.copy(), copy.deepcopy()
- special method names:
basic customization
and customization for
numeric types (overloading +, *, etc.)
- __dict__
- functions with default values for parameters
- dictionaries: .keys(), .values(), .items(), .copy(), .get()
- pickle library (we didn't cover in lecture; read up on it if you want to
use it)