turtle.left() function in Python

The turtle.left() function in Python rotates the turtle counter-clockwise (left) by a specified angle. This only changes the turtle’s heading, not its position.

Syntax: turtle.left(angle)
Parameters: angle: a number (integer or float) representing the degrees to turn.

Let us see an example to implement the turtle.left() function in Python:

Demo3.py

# turtle.left() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.forward(100)
t.left(90)      # Turn left 90 degrees
t.forward(100)

window.exitonclick()

The following is the output:

turtle.left() in Python Turtle

In the above code, we followed the below steps:

  • Import the module: import turtle loads Python’s turtle graphics library so you can draw with a virtual “pen.”
  • Create the screen: window = turtle.Screen() opens the drawing window where movement is shown.
  • Create the turtle: t = turtle.Turtle() creates a turtle object you’ll control.
  • Move forward:forward(100) moves the turtle 100 units in its current direction, drawing a line.
  • Turn left:left(90) rotates the turtle 90 degrees counterclockwise without moving.
  • Move forward again:forward(100) draws another 100-unit line in the new direction, forming an “L” shape.
  • Close on click: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:

turtle.backward() function in Python
turtle.right() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment