Open In App

turtle.home() function in Python

Last Updated : 21 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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).

Syntax :

turtle.home()

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle
  
  
# check turtle position
print(turtle.position())
  
# motion
turtle.forward(100)
  
# check turtle position
print(turtle.position())
  
# set turtle to home
turtle.home()
  
# check turtle position
print(turtle.position())
  
# motion
turtle.right(90)
turtle.forward(100)
  
# check turtle position
print(turtle.position())
  
# set turtle to home
turtle.home()
  
# check turtle position
print(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 package
import turtle
  
  
# set turtle speed to fastest
# for bettrt understandings
turtle.speed(10)
  
# method to draw a part
def fxn():
    
  # motion
  turtle.circle(50,180)
  turtle.right(90)
  turtle.circle(50,180)
  
# loop to draw pattern
for i in range(12):
  fxn()
    
  # set turtle at home
  turtle.up()
  turtle.home()
  turtle.down()
    
  # set position
  turtle.left(30*(i+1))


Output :



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads