Wednesday, October 1, 2025
HomeLanguagesturtle.clearstamps() method in Python

turtle.clearstamps() method in Python

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.clearstamps()

The turtle.clearstamps() method is used to delete all or first/last n of turtle’s stamps. This method requires an argument of an integer. So, the n stamps made are cleared by it.

Syntax : turtle.clearstamps(n=None)

Optional argument: n — an integer

  • If n is None, delete all of pen’s stamps,
  • else if n > 0 delete first n stamps
  • else if n < 0 delete last n stamps.

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

Example 1 :

Python3




# import package
import turtle 
  
  
# set turtle speed to slowest 
# for better understandings
turtle.speed(1)
  
# motion with stamps
turtle.forward(50)
turtle.stamp()
turtle.forward(50)
turtle.stamp()
turtle.forward(50)
turtle.stamp()
  
# hide the turtle to
# clarify stamps
turtle.ht()
  
# clear the all stamps
turtle.clearstamps()


Output :

Example 2 :

Python3




# import package
import turtle 
  
  
# loop to create motion
# with stamps
for i in range(12):
      
    # motion
    turtle.forward(50)
      
    # stamp
    turtle.stamp()
    turtle.right(30)
  
# hide the turtle for 
# better understandings
turtle.ht()
  
# clear the first 8 stamps
turtle.clearstamps(8)


Output :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6815 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS