Types, Operators, and Precedence
Types
We know about four or five types. What are they?
- str
- int
- float
- bool
- (complex)
Functions
What's a function? We know about seven built-in functions. What are they? What values do they expect? What do they return?
- print - doesn't return anything
- type
- int
- str
- float
- bool
- input - always returns a string!
Types and Operations
What are some numeric operations that we've used?
(you can mix and match numeric types, but not other types)
Types and Operations (Continued)
What are some string operations that we've used?
- + - concatenation - only strings
- * - multiplication - string and int!
Let's Talk About Comparison Operators
What are the six comparison operators that we learned about, and how do they work with different types?
- == - different types always return False
- != - different types always return True
- < - different non numeric types result in an error
- > - different non numeric types result in an error
- >= - different non numeric types result in an error
- <= - different non numeric types result in an error
Let's Talk About Logical Operators
What are the three logical operators that we learned about? Describe when each would return True. →
- and - evaluates to True if both operands are True
- or - evaluates to True if either operand is True
- not - evaluates to True if operand is False
What Order Do All of These Operators Go In?
So. With all of these types of operations, what order are they evaluated in? →
- Parentheses
- Numerical/String operators
- Comparison operators
- Logical operators
- not
- and
- or
Let's Try a Few…
What boolean value does the following expression evaluate to? →
Aaaaand… how about this one? →
Logical Operators and Their Operands
How many operands does each logical operator take… what type is each operand? →
- and - 2 operands - values are treated as boolean
- or - 2 operands - values are treated as boolean
- not - 1 operands - values is treated as boolean
Watch Out for This!
Let's write a boolean expression that checks if the variable, answer, is equal to "yes" or "yeah": →
Note that the following won't work!
let's try both versions with answer set as "no" →
Conditionals
- syntax - if, boolean expression, colon, indented body
- note that the end result of comparisons… are essentially the same as bare literal
- some example code I have takes the shortcut of putting in the bool literal