Python
This lecture is a fast-paced introduction to Python, a scripting language that is increasingly popular in computational science.
Requires: some previous experience of programming, and know at least a little about loops, lists, if statements, functions, and file I/O.
Introduces: Python language basics
- Introduction (pdf, ppt)
- Human time vs. machine time
- Why Python
- Basics (pdf, ppt)
- Running Python
- Variables and values
- Numbers and arithmetic
- In-place operators
- Comparisons
- Control Flow (pdf, ppt)
- While loops
- Conditionals
- Lists (pdf, ppt)
- Mutable and heterogeneous
- Creating, getting, and setting
- Negative indices
- For loops
- Deleting and appending
- Methods
- Ranges
- Input and Output (pdf, ppt)
- Opening and reading files
- Looping over file contents
- Writing to files
- Several ways to copy a file
- Strings (pdf, ppt)
- Text vs. binary data
- Indexing
- Quoting
- Escape characters
- Immutability
- Concatenation
- Formatting
- Methods
- Aliasing (pdf, ppt)
- Definition
- Irrelevant for immutable values
- List example
- Example aliasing bug
- Functions (pdf, ppt)
- Defining functions
- Parameters
- The call stack and stack frames
- The return statement
- Copying and aliasing
- Default parameter values
- When and why to write functions
- First-Class Functions (pdf, ppt)
- Binding functions to variables
- Passing functions to functions
- Re-using control flow
- Programming as creating and combining abstractions
- Libraries (pdf, ppt)
- Files as modules
- The import statement
- Namespaces
- The math library
- The sys library
- Docstrings
if __name__ == '__main__'
- Tuples (pdf, ppt)
- Have to wait to see why they’re necessary
- Creating and indexing
- Multi-valued assignment
- Unpacking lists
- Slicing (pdf, ppt)
- Slicing vs. indexing
- Silent truncation
- Aliasing
- Text (pdf, ppt)
- How lines are stored
- How characters are stored
- Unicode and UTF-8
- Why you care
Exercises
Reading

Great quick little python overview. Thanks.
first = first.append(‘newton’) – slide #52 in the pdf file
This should produce “None”?
@Tanya
Heh, which of the pdf files?
I’m assuming is the “aliasing” episode – if not, please correct me.
You are correct. As written there, first should have the value of None, and most operations over that variable would fail. And there would be no aliasing, with first and second referring to different objects (second to a list, and first to None).
I believe that (those) slide(s) should read:
first = ['isaac']
second = first
first.append(‘newton’)
…
With no assignment after the append()
Thanks for noticing.
Luis.
@luis
Thanks! You are right – it’s the pdf for the “Aliasing” lecture.
Wow! Just had a look at your site. I must say, these tutorials are as good as it gets.
Keep it up!