In Python’s Turtle module, you can control how the turtle draws on the screen using penup(), pendown(), and color(). You can fill shapes with a color using begin_fill(), end_fill() and fillcolor().

Examples:

  1. Using penup() and pendown():

    import turtle as t
    
    t.forward(50)    # Draws a line 50 units long
    t.penup()        # Lifts the pen up
    t.forward(50)    # Moves forward 50 units without drawing
    t.pendown()      # Puts the pen down
    t.forward(50)    # Draws another line 50 units long
    

    In this example, the turtle draws a line, moves without drawing, and then draws another line.

  2. Changing the pen color with color():

    import turtle as t
    
    t.color('red')   # Sets the pen color to red
    t.forward(100)   # Draws a red line
    t.penup()
    t.forward(50)    # Moves forward 50 units without drawing
    t.pendown()
    t.color('blue')  # Changes the pen color to blue
    t.forward(100)   # Draws a blue line
    

    This example shows how to change the pen color and draw lines in different colors.

  3. Drawing a filled circle with begin_fill(), end_fill() and fillcolor():

    import turtle as t
    
    t.color('red')         # Sets the pen color to red
    t.fillcolor("yellow")  # Sets the fill color to yellow
    t.begin_fill()         # Start filling the shape
    t.circle(50)           # Draws a circle with a radius of 50 units
    t.end_fill()           # Fill the circle with yellow color
    

    This example shows how to draw and fill a circle.

By using penup(), pendown(), and color(), you can create drawings where the turtle moves around the screen, drawing lines only when you want it to, and in the colors you choose. By using begin_fill() and end_fill(), you can easily create filled shapes like circles, squares, and other polygons.

If you want to experiment, you can do it online on trinket.io/turtle1.

Summary

Command Explanation
penup() The pen is lifted from the canvas and doesn’t draw when moving.
pendown() The pen is pressed against the canvas and draws when moving.
color("c") Choose the colour named c.
begin_fill() Start colouring a shape.
end_fill() Stop colouring a shape.
fillcolor("c") Choose the colour to fill the inside of a shape named c.
stamp() Show where the turtle is.

Use these sources to find more information: