COMPSCI 101L Chapter Notes - Chapter 4, 7, 9: Empty String, Substring, Decimal Mark
Computer Science
Reading Notes: Chapter 4.4-4.6, 7.1-7.5, 9.1-9.7
Chapter 4
- For loops
o For loop_variable in [sequence]:
▪ Sequence can be number sequence (1,2,3,4) or even letter sequence (“a”,
“b”, “c”, “d”)
▪ Loop variable can be any valid name
▪ Whatever comes next after colon will be indented (indent statements are
called the loop body)
o For a loop to stop, all items in the sequence must have their turn
- For loops is our first example of a compound statement
Chapter 7
- A new data type, bool (like the data type int or float)
- Two Boolean values: True and False
o Boolean values are not strings
- A Boolean expression is an expression that evaluates to a Boolean values
- Ex: print(5==6) will print False
- Works with comparison/relationship (==, >=, <=, !=, >, <) and logical operators (and, or,
not)
- What is the precedence: Comparison operators operate before the logical operators
o Arithmetic operators have a higher precedence than all of them
o Parentheses can be used to force precedence
- Selection statements or conditional statements give us the ability to check conditions and
change the behavior of the program accordingly
o Simplest form is the “if statement” or the “binary selection”
o If some Boolean expression is true, perform this statement. If not (or else),
perform this other statement.
o There can at least one or more statements in the if and else blocks
- Unary selection: using an if statement with the else statement omitted
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
For loops: for loop_variable in [sequence], sequence can be number sequence (1,2,3,4) or even letter sequence ( a , For loops is our first example of a compound statement. A new data type, bool (like the data type int or float) Two boolean values: true and false: boolean values are not strings. A boolean expression is an expression that evaluates to a boolean values. Works with comparison/relationship (==, >=, <=, !=, >,