Open In App

turtle.heading() function in Python

Last Updated : 19 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

turtle.heading() function returns the current orientation (angle) of the turtle in degrees. The angle is measured counterclockwise from the positive x-axis (east direction), with the initial default heading being 0.0. This function simply provides the current direction in which the turtle is facing, making it useful for tracking movement and controlling drawing patterns

Syntax :

turtle.heading()

Examples

Example 1: Default Heading

Python
import turtle
print(turtle.heading())

Output:

0.0

Explanation: turtle.heading() returns the current direction (in degrees). At the start, the turtle faces east (default), so the heading is 0.0.

Example 2: Heading Values While Moving

Python
import turtle
turtle.speed(1)

for i in range(4):
    turtle.forward(100)
    val = turtle.heading()
    turtle.write(str(val))
    turtle.backward(100)
    turtle.left(90)

Output:

Explanation:

  • turtle.forward(100) moves the turtle ahead, and turtle.backward(100) brings it back to the start.
  • turtle.heading() gets the current direction (0°, 90°, 180°, 270°), and turtle.write(str(val)) displays it on the canvas.
  • turtle.left(90) rotates the turtle left by 90°, updating the heading step by step.

Article Tags :
Practice Tags :

Similar Reads