Saturday lecture notes

Friday review

math

In [None]:
 

type()

In [None]:
 

variables

In [None]:
 

strings

In [None]:
 

booleans

In [None]:
 

if/elif/else

In [None]:
 

functions

In [None]:
 

Lists

In [None]:
 

purpose

Conveniently handle bunches of data that will all need to be treated together!

initialization

In [None]:
 

len() review

In [None]:
 

accessing elements

In [None]:
 

adding elements

In [None]:
 

changing elements

In [None]:
 

slicing lists

In [None]:
 

strings are like lists

In [None]:
 

loops and more flow control

for loops

In [None]:
 

if statements inside for loops

In [None]:
 

nested for loops

In [None]:
 

range()

In [None]:
 

while loops

In [None]:
 

infinite loops

In [None]:
 

if statements inside while loops

In [None]:
 

break

In [None]:
 

raw_input()

In [None]:
 

dictionaries

purpose

Think of a phone book!

initialization

In [None]:
 

accessing elements

In [None]:
 

adding elements

In [None]:
 

changing elements

In [None]:
 

keys() and values()

In [None]:
 

modules

purpose

  • Don't write it twice!
  • Don't write it at all!

builtins

In [None]:
 

imports

In [None]:
import random
In [None]:
random.randint(1, 100)
In [None]:
random.choice([2, 8, 'twelve'])

Putting it all together

capitals.py, a quiz game

Back to top