← Python lessons

penup() and pendown()

Part of a free Python course — sign up to save your progress and get AI hints.Sign up free

penup() lifts the turtle's pen so it moves without drawing, and pendown() puts the pen back down so it draws again.

Move without drawing

import turtle

t = turtle.Turtle()
t.forward(50)
t.penup()
t.forward(50)
t.pendown()
t.forward(50)

The turtle moved 150 steps but drew two lines with a gap between them. The pen stays up until you call pendown().

Draw shapes in different places

To start a new shape somewhere else, lift the pen, goto() the new start, then put the pen down:

import turtle

t = turtle.Turtle()
t.penup()
t.goto(-150, 0)
t.pendown()
t.goto(-50, 0)
t.goto(-100, 80)
t.goto(-150, 0)
t.penup()
t.goto(50, 0)
t.pendown()
t.goto(150, 0)
t.goto(100, 80)
t.goto(50, 0)

Two triangles, and no line joins them.

Check the pen with isdown()

isdown() is True while the pen is down and False while it is up.

import turtle

t = turtle.Turtle()
print(t.isdown())
t.penup()
print(t.isdown())

Jump with teleport()

teleport(x, y) jumps straight to a point without drawing, even with the pen down. The pen stays the way it was.

import turtle

t = turtle.Turtle()
t.forward(100)
t.teleport(0, 50)
t.forward(100)
print(t.isdown())

Two lines, one above the other. One teleport() does the job of penup(), goto() and pendown().

Note: teleport() is new in Python 3.12. On an older Python, use penup(), goto() and pendown(). up() and down() are short names for penup() and pendown().

See also: Turtle coordinates, Turtle colours.

Your turn

Add two lines: lift the pen, then move forward 40 more steps without drawing.

import turtle

t = turtle.Turtle()
t.forward(40)
# add two lines: lift the pen, then move forward 40
print(t.isdown())
print(t.xcor())

Expected output

False
80.0