turtle.sety() function in Python (original) (raw)
Last Updated : 14 Aug, 2025
turtle.sety()method moves the turtle to a specified y-coordinate while keeping its current x-coordinate and heading (direction) unchanged. If the pen is down, it will draw a line from the current position to the new y-coordinate; if the pen is up, it moves without drawing.
**Syntax:
turtle.sety(y)
- **Parameters: y (int | float) is the y-coordinate to move the turtle to.
- **Returns: This method only changes the turtle's vertical position on the screen.
Examples of turtle.sety() function
**Example 1 : Simple vertical movement
Python `
import turtle
print(turtle.position()) # Initial position turtle.sety(30) print(turtle.position()) # After moving up turtle.sety(-50) print(turtle.position()) # After moving down
turtle.done()
`
**Output :
(0.0, 0.0)
(0.0, 30.0)
(0.0, -50.0)
**Explanation: The turtle’s y-coordinate changes to 30, then to -50, while the x-coordinate remains 0.
**Example 2 : Drawing with y-coordinate changes
Python `
import turtle
for i in range(4): turtle.forward(100) turtle.right(90) turtle.forward(20) turtle.right(90) turtle.forward(100)
turtle.penup()
turtle.sety(-40 * (i + 1))
turtle.pendown()
turtle.left(180)turtle.done()
`
**Output

**Explanation: The turtle draws repeated vertical patterns, then uses sety() to jump down to the next row without affecting the x-coordinate.