Turtle is a Python Module which allows us to draw a various geometrical illustration by just importing it in Python and using the inbuilt function of the turtle Module. We can use functions like turtle.forward(…) and turtle.right(…) which can move the turtle around. Turtle is a beginner-friendly way to learn python by running some basic commands and viewing the turtle do it graphically. It is like a drawing board that allows you to draw over it. The turtle module can be used in both object-oriented and procedure-oriented ways.
Turtle methods used are as follows:
Functions used for moving the turtle
|forward(no. of steps)||This function is used to move the turtle forward the specified number of steps.|
|backward(no. of steps)||This function is used to move the turtle forward the specified number of steps.|
|left(angle)||This function is used to rotate the turtle left/anti-clockwise with the specified angle.|
|right(angle)||This function is used to rotate the turtle right/clockwise with the specified angle.|
Function used for knowing the turtle’s state:
position()– This function is used to get the coordinates/position of the turtle pointer. No parameter is required here as this function is not used for giving input but is used to output the position of turtle in the console window.
Functions used for colouring:
|bgcolor(“color”)||This function is used to give background color to the turtle window.|
|pencolor(“color”)||This function is used to give color to the turtle pen.|
|fillcolor(“color”)||This function is used to fill color in any closed shape.|
|color(pencolor, fillcolor)||This is a shorthand function used to assign pencolor and fillcolor at the same time.|
Function used for pen control:
|penup() or pu()||This function is used to lift pen from the current position.|
|goto()||This function is used to move the pen to a new location after lifting.|
|pendown() or pd()||This function is used again put down the pen to a new location.|
|pensize(int)||This function is used to specify the width of the line drawn by pen.|
Note: To know more about turtle click here.
After having learned the basics of turtle, let’s write the code for printing ‘HELLO’. Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.