turtle commands python code example

Example 1: turtle python

from turtle import *
color('red', 'yellow')
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()

Example 2: python turtle example

# Step 1: Make all the "turtle" commands available to us.
import turtle

# Step 2: Create a new turtle. We'll call it "bob"
bob = turtle.Turtle()

# Step 3: Move in the direction Bob's facing for 50 pixels
bob.forward(50)

# Step 4: We're done!
turtle.done()

Example 3: turtle with python

import turtle
#creating a square with turtle
t = turtle.Turtle()
t.forward(100)
t.color('blue')
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)

Example 4: python turtle tutorial

>>> turtle.pos()
(440.00,-0.00)

Example 5: python turtle tutorial

>>> turtle.position()
(0.00,240.00)
>>> turtle.setx(10)
>>> turtle.position()
(10.00,240.00)

Example 6: python turtle tutorial

>>> s = turtle.getscreen()