Open In App

turtle.speed() function in Python

Last Updated : 20 Mar, 2025
Suggest changes
Share
Like Article
Like
Report

The turtle module in Python enables graphics and animations using Tkinter. It supports object-oriented and procedural approaches. The turtle.speed() method is used to control the speed of the turtle's movement. It accepts a numerical value or a predefined string and adjusts the turtle's speed accordingly.

Example:

Python
# import package import turtle # slowest speed turtle.speed(1) # turtle movement turtle.forward(150) 

Output

Explanation: In this example, the turtle's speed is set to the slowest (speed(1)), meaning its movement will be slow and deliberate. It then moves forward by 150 units in a straight line.

Syntax of turtle.speed():

turtle.speed(speed=None)

Parameters: speed: (Optional) An integer between 0 and 10 or a predefined speed string.

Speed Values:

The speed range is 0-10, where:

  • 0 (fastest) → No animation, instant movement
  • 1 (slowest) → Slowest speed
  • 3 (slow) → Slower than normal
  • 6 (normal) → Default speed
  • 10 (fast) → Fastest animation

If a value greater than 10 or less than 0.5 is provided, the speed is automatically set to 0.

Examples of turtle.speed()

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

Example 1: Speed Variation in a Pattern

Python
# import package import turtle # loop for pattern for i in range(10): # set turtle speed turtle.speed(10-i) # motion for pattern turtle.forward(50+10*i) turtle.right(90) 

Output

Explanation: The loop decreases the turtle's speed from 10 to 1, while it moves forward by an increasing distance (50 + 10*i) and turns right by 90 degrees, creating a slowing spiral pattern.

Example 2: Speeding Up After Every Move

Python
import turtle turtle.speed(1) # Start with the slowest speed for i in range(1, 11): turtle.speed(i) # Increase speed gradually turtle.forward(20 * i) turtle.right(45) turtle.done() 

Output

Output
Speeding Arrows

Explanation: Turtle starts at speed 1 and increases speed with each iteration while moving forward and turning right by 45 degrees.

Example 3: Using Predefined speed strings

Python
import turtle turtle.speed("fast") # Use predefined speed string turtle.circle(100) # Draw a circle with radius 100 turtle.done() 

Output

output777
Circle

Explanation: Turtle moves quickly ("fast", speed 10) to draw a circle with a radius of 100. The drawing is nearly instant but animated. Setting speed(0) makes it instant without animation.


Similar Reads

Article Tags :
Practice Tags :