turtle.sety() function in Python
Last Updated :
30 Jun, 2021
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.sety()
This method is used to set the turtle’s second coordinate to y, leaving the first coordinate unchanged. Here, whatever the position of the turtle is, it set the y coordinate to given input keeping the x coordinate unchanged.
Syntax : turtle.sety(y)
Parameter:
y: a number (integer or float), it is the only one required argument.
Below is the implementation of the above method with some examples :
Example 1 :
Python3
import turtle
print (turtle.position())
turtle.sety( 30 )
print (turtle.position())
turtle.sety( - 50 )
print (turtle.position())
|
Output :
(0.0, 0.0)
(0.0, 30.0)
(0.0, -50.0)
Example 2 :
Python3
import turtle
for i in range ( 4 ):
turtle.forward( 100 )
turtle.right( 90 )
turtle.forward( 20 )
turtle.right( 90 )
turtle.forward( 100 )
turtle.up()
turtle.sety( - 40 * (i + 1 ))
turtle.down()
turtle.left( 180 )
|
Output :