17 Sep turtle.seth() function in Python
The turtle.seth() function in Python sets the turtle’s heading (direction it is facing) to the specified angle. 0 is east, 90 is north, 180 is west, 270 is south.
Syntax: turtle.seth(to_angle)
Parameters: to_angle: a number (integer or float) representing the new heading in degrees.
Let us see an example to implement the turtle.seth() function in Python:
Demo7.py
# turtle.seth() function in Python # Code by Studyopedia import turtle window = turtle.Screen() t = turtle.Turtle() t.seth(45) # Set heading to 45 degrees (northeast) t.forward(100) t.seth(180) # Set heading to 180 degrees (west) t.forward(100) window.exitonclick()
The following is the output:

In the above code, we followed the below steps:
- Import the module: import turtle loads Python’s turtle graphics library for drawing.
- Create the screen: window = turtle.Screen() opens the drawing window.
- Create the turtle: t = turtle.Turtle() creates the turtle (the pen) you’ll control.
- Set absolute heading to 45°: t.seth(45) points the turtle northeast. This rotates without moving; headings are absolute (0° east, 90° north, 180° west, 270° south).
- Move forward 100: t.forward(100) draws a 100-unit line along the 45° direction.
- Set absolute heading to 180°: t.seth(180) reorients the turtle to face west, again without moving its position.
- Move forward 100: t.forward(100) draws a 100-unit line to the left from the current point.
- Close on click: window.exitonclick() keeps the window open until you click inside it, then closes.
If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- OpenCV Tutorial
- Python Tutorial
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- Generative AI Tutorial
- LangChain Tutorial
- RAG Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments