Chapter 3 - Main Ideas

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