Chapter 3 - Main Ideas
- Python "operators" help code do things with values and variables:
- assignment operator:
- addition operator:
x = 1 + 2y = x + 3message = "hello" + " world"
- subtraction, multiplication, division, and modulus operators:
x = 1 - 2x = a * bx = 16 / 2x = 3 % 2
- parentheses change the order of operations
x = 8 + 4 / 2y = (8 + 4) / 2
- "shortcut operators" - add and assign and subtract and assign
x += 1 # same as x=x+1x -= 1 # same as x=x-1
- constants - like variables but their value never changes
RIGHT_ANGLE = 90PI = 3.14
- format strings
player.speak(f"Coup has {chickens} chickens")- old style -
player.speak("Coup has %d chickens" % (chickens))