Beginning Python: Value Types
2025-10-01
python:
.py fileqmd)python skills:
print()+, -)=type() functionTwo types:
We’ve seen two operators already:
x + y (add)x - y (subtract)Here are two more:
x * y (multiply)x / y (divide)python, compute the following equations:Operators:
x ** y (exponent)x % y (modulus: remainder)modulus command is actually quite useful, as it shows us when one number is not evenly divisible by another.x // y (floor division)10 // 3 # 3 (3 goes into 10 three times, remainder dropped)
14 // 5 # 2 (5 goes into 14 two times, remainder dropped)Divide 100 by 9 three different ways:
///%How many full weeks and leftover days are in a full year?
type() functionIf you type text without quotes:
With quotes:
Assigning strings:
Concatenate with +:
We could also print it this way:
What happens when we run this code?
\".
\#, etc." (and '), almost any character can be within a string.type() functionOnly two: True, False.
Usually created by comparisons:
Important!
= means variable assignment== means equals or testing if two things are equal== is exactly equal to!= is not equal to> greater than>= greater than or equal to< less than<= less than or equal tonot flips a booleanand is true if both are trueor is true if at least one is trueCheck for Andrew with “w” or without:
Check for Andrew, who is 46:
Check for Andrew, who is not 45:
Steps:
word.
word[0].starts_p, starts_t, starts_k
starts_p = word[0] == "p", etc.aspirated, whose value is True if any of the above is True.
orword = "pin" # try: "spin", "top", "stop", "cat", "skat"
# Step 1: check if word starts with a voiceless stop
starts_p = word[0] == "p"
starts_t = word[0] == "t"
starts_k = word[0] == "k"
# Step 2: decide aspiration (simplified: only if it’s the first sound)
aspirated = starts_p or starts_t or starts_k
print("Word:", word)
print("Aspirated?", aspirated)# Step 1: check if word starts with a voiceless stop
starts_p = word[0] == "p"
starts_t = word[0] == "t"
starts_k = word[0] == "k"
# Step 2: decide aspiration (simplified: only if it’s the first sound)
aspirated = starts_p or starts_t or starts_k
print("Word:", word)
print("Aspirated?", aspirated)