Outline for May 6, 2009
Reading: §8.4–8.6
- Booleans
- Values are True, False
- Values considered False: None, False, 0 of any type, empty string,
empty list, empty sequence; all others True
- Variable assignment
- Short-circuit evaluation
- Operators and truth tables
- and, or, not
- A and B, A or B, not A
- Basic rules of Boolean algebra
- A and true == A, A and false == false
- A or true == true, A or false == A
- not (not A) == A
- Distributive laws
- A or (B and C) == (A or B) and (A or C)
- A and (B or C) == (A and B) or (A and C)
- De Morgan’s Laws
- not (A or B) == (not A) and (not B)
- not (A and B) == (not A) or (not B)
- Combining operations
- Precedence: who “binds” more tightly
- Here, “not” highest precedence; then
“and”; then “or”
- a or not b and c is (a or ((not b) and c))
- c. Relational operators have higher precedence
- a == b and c == d is ((a == b) and (c == d))
- Danger: response == "Y" or "y" doesn’t do what you think
- Other types of loops
- break, continue (see
loop1.py)
- Post-test (repeat ... until); put test at bottom
- Loop and a half (see
loop2.py)
- Example (see
sent2.py)