Turtle Graphics

Drawing a Square with Turtle

The code section below draws a square on the screen using the turtle library:

import turtle

turtle.pensize(5)
turtle.pencolor("Red")

turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)

turtle.done()

The import directive tells the python interpreter to use the turtle library. There are many built-in libraries that you can make use of for your software projects as listed in https://docs.python.org/3/library . You should use a different import line at the top of the source code file for each library you need to use, for example:

import turtle
import math
import io
import time
import os
import random

You can check for the detailed tutorial on turtle library from https://docs.python.org/3/library/turtle.html