How to get the position of the turtle?

Viewed 36427

How can I find the coordinate of a turtle in python?

For example, if the turtle is located at (200, 300), how would I retrieve that position?

4 Answers

As shown in the Python documentation, turtle.pos() returns the turtle’s current location as a 2D vector of (x,y).

Well the turtle.pos() method returns a tuple

A Vector is derived from tuple, so a vector is a tuple!

so you can check if the turtle is at a specific coordinate by using:

if turtle.pos() == (5.0, 0.0):
    print(“at coordinate”)
Related