Skip to main contentdfsdf

Tim Isganitis's List: Learning Python

  • Python for Non-Programmers

  • May 20, 10

    This book is used as a reference for teaching Python in MIT's intro CS course. It is a simple and concise presentation of basic programming concepts in either Python or Java. It is of higher quality than Blue Pelican Java. It defers discussion of OOP until after discussing basic programming concepts.

  • Beginning Python for Programmers

    • When a python file is run directly, the special variable "__name__" is set to "__main__". Therefore, it's common to have the boilerplate if __name__ ==... shown above to call a main() function when the module is run directly, but not when the module is imported by some other module.
    • In a standard python program, the list sys.argv contains the command line arguments in the standard way with sys.argv[0] being the program itself, sys.argv[1] the first argument, and so on.

    5 more annotations...

    • Python has a built-in string class named "str" with many handy features (there is an older module named "string" which you should not use).
    • A string literal can span multiple lines, but there must be a backslash \ at the end of each line to escape the newline. String literals inside triple quotes, """" or ''', can multiple lines of text.

    17 more annotations...

    • Python has a great built-in list type named "list". List literals are written within square brackets [ ]. Lists work similarly to strings -- use the len() function and square brackets [ ] to access data, with the first element at index 0.
    • The *for* construct -- for var in list -- is an easy way to look at each element in a list (or other collection). Do not add or remove from the list during iteration.

    3 more annotations...

    • Python's efficient key/value hash table structure is called a "dict". The contents of a dict can be written as a series of key:value pairs within braces { }, e.g. dict = {key1:value1, key2:value2, ... }. The "empty dict" is just an empty pair of curly braces {}.
    • Looking up or setting a value in a dict uses square brackets, e.g. dict['foo'] looks up the value under the key 'foo'. Strings, numbers, and tuples work as keys, and any type can be a value.

    5 more annotations...

1 - 7 of 7
20 items/page
List Comments (0)