Learn > BGE > Python – Turtle Graphics > 4. Variables

Variables

A variable is used to store information that can change. Variables are useful because they let us reuse values instead of typing the same numbers again and again. For example, we can store:

  • the distance the turtle moves
  • the angle the turtle turns
from turtle import *
screen = getscreen()
tom = Turtle()

distance = 200
angle = 90

for counter in range(4):
    tom.forward(distance)
    tom.right(angle)

Variable Benefits

  • Makes code easier to change
    You only need to change the value once.
  • Makes code easier to read
    Variable names help explain what numbers are used for.
  • Reduces mistakes
    You do not need to retype the same number many times.