Join 36000+ teachers and students using TTIO.
Just like we can have many different integers in a program, we can have many turtles. Each of them is an independent object and we call each one an instance of the Turtle type (class). Each instance has its own attributes and methods — so alex might draw with a thin black pen and be at some position, while tess might be going in her own direction with a fat pink pen.
import turtle
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor("lightgreen")
adam = turtle.Turtle() #create adam and set some attributes
adam.color("hotpink")
adam.pensize(5)
eve = turtle.Turtle() # create eve
adam.forward(80) # Let adam draw an equilateral triangle
adam.left(120)
adam.forward(80)
adam.left(120)
adam.forward(80)
adam.left(120) # complete the triangle
adam.right(180) # turn adam around
adam.forward(80) # move him away from the origin
eve.forward(50) # make eve draw a square
eve.left(90)
eve.forward(50)
eve.left(90)
eve.forward(50)
eve.left(90)
eve.forward(50)
eve.left(90)
wn.exitonclick()
www.teachyourselfpython.com