The Wayback Machine - https://web.archive.org/web/20240109045531/https://www.geeksforgeeks.org/turtle-heading-function-in-python/
Open In App
Related Articles

turtle.heading() function in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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.heading()

This function is used to return the turtle’s current heading. It doesn’t require any argument.

Syntax :

turtle.heading()

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

Example 1 :

Python3




# import package
import turtle
 
# default heading value
print(turtle.heading())


 

 

Output :

 

0.0

 

Example 2 :

 

Python3




# import package
import turtle
 
# set turtle speed
# for better understandings
turtle.speed(1)
 
# loop for pattern
for i in range(4):
    turtle.forward(100)
     
    # get heading value
    val = turtle.heading()
     
    # write it
    turtle.write(str(val))
    turtle.backward(100)
    turtle.left(90)


 

 

Output :

 

 

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 14 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials