turtle.home() function in Python
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
turtle.home()
This function is used to move the turtle to the origin i.e. coordinates (0,0). Whatever, the position of the turtle is, it sets to (0,0) with default direction (facing to east).
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Syntax :
turtle.home()
Below is the implementation of the above method with some examples :
Example 1 :
Python3
# import packageimport turtle # check turtle positionprint(turtle.position()) # motionturtle.forward(100) # check turtle positionprint(turtle.position()) # set turtle to hometurtle.home() # check turtle positionprint(turtle.position()) # motionturtle.right(90)turtle.forward(100) # check turtle positionprint(turtle.position()) # set turtle to hometurtle.home() # check turtle positionprint(turtle.position()) |
Output :
(0.0, 0.0) (100.0, 0.0) (0.0, 0.0) (0.0, -100.0) (0.0, 0.0)
Example 2 :
Python3
# import packageimport turtle # set turtle speed to fastest# for bettrt understandingsturtle.speed(10) # method to draw a partdef fxn(): # motion turtle.circle(50,180) turtle.right(90) turtle.circle(50,180) # loop to draw patternfor i in range(12): fxn() # set turtle at home turtle.up() turtle.home() turtle.down() # set position turtle.left(30*(i+1)) |
Output :



