Types, Operators, and Precedence

Types

We know about four or five types. What are they?

Functions

What's a function? We know about seven built-in functions. What are they? What values do they expect? What do they return?

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?

Let's Talk About Comparison Operators

What are the six comparison operators that we learned about, and how do they work with different types?

Let's Talk About Logical Operators

What are the three logical operators that we learned about? Describe when each would return True.

What Order Do All of These Operators Go In?

So. With all of these types of operations, what order are they evaluated in?

  1. Parentheses
  2. Numerical/String operators
  3. Comparison operators
  4. Logical operators
    1. not
    2. and
    3. or

Let's Try a Few…

What boolean value does the following expression evaluate to?

"five" == 5 or  14 == 7 + 2 * 5
False

Aaaaand… how about this one?

False or True and not False
True

Logical Operators and Their Operands

How many operands does each logical operator take… what type is each operand?

Watch Out for This!

Let's write a boolean expression that checks if the variable, answer, is equal to "yes" or "yeah":

answer == "yes" or answer == "yeah"

Note that the following won't work!

#  the logical operator, or, tries to treat "yeah" as a bool
answer == "yes" or "yeah"

let's try both versions with answer set as "no"

>>> answer = "no"
>>> answer == "yes" or answer == "yeah"
False
>>> answer == "yes" or "yeah"
'yeah'

Conditionals

a, b = 1, 1
if a == b or b == 1 or a == 1:
	print("true")

if True:
	print("true")

How to (Un)Complicate Things With If Statements