Skip to content

C. shape(): Changing the Turtle Shape

To the final mission: โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 30%


๐ŸŽฏ Learning Goals

By the end of this lesson, you'll be able to:

  • โ—‹ shape() You can use a function
  • โ—‹ Understands why strings need quotation marks
  • โ—‹ Can learn about various shape options

โšก 30-Second Challenge

Run the code below and try changing the shape!

Did it work? Let's learn more about it below!


Core Concepts

What is shape()?

shape('turtle')sets the turtle's shape.


โš ๏ธ Quotation marks matter!

'turtle'like Quotes You need to put the shape name inside.

โŒ Wrong Code

t.shape(turtle)     # No quotation marks!
Error: Python turtleIt tries to find it as a variable

โœ… Correct Code

t.shape('turtle')   # Has quotation marks!
Normal: Python 'turtle'It recognizes it as a string


Available shapes

Code Shape Description
'turtle' ๐Ÿข Turtle (default)
'arrow' โžก๏ธ Arrow (to show direction)
'circle' โšซ Circle
'square' โฌ› Square
'triangle' ๐Ÿ”บ Triangle

Try Visual Coding

๐ŸŽฏ Mission
โ—‹ Add a "shape" block and pick a different shape from the dropdown!
# Add blocks and the Python code will show up here...
Add blocks and the flowchart will show up here...


Example Code

import turtle
t = turtle.Turtle()
t.shape("arrow")    # Change to an arrow shape!

What Happens

An arrow shape appears on the screen!


Quiz

Quiz: using quotes
What should you put in the blank to set the turtle shape?
t.shape(____)
Show Answer

Answer: 'turtle'

Strings must be wrapped in quotes!


๐Ÿ”ง Debug Clinic

Problem: a NameError occurs!

โŒ Wrong Code

t.shape(turtle)    # Python: "Where is the variable called turtle?"
Cause: shape(turtle) - You forgot the quotes!

โœ… Correct Code

t.shape('turtle')  # Python: "Oh, it's the string 'turtle'!"
Fix: shape('turtle') - Add quotes!


Try Coding It Yourself

Take what you learned with the blocks and write it yourself in Python code!

Change shape

t.shape()Change the turtle's shape with it.

Example Answer
import turtle
t = turtle.Turtle()

t.shape('arrow')

Result: an arrow shape appears on the screen!


shape() syntax practice

  • Change to an arrow: t.shape('arrow')
  • Turning it into a circle: t.shape('circle')
  • A string QuotesWrap it with (' Or ")

Review Checklist

  • [ ] shape() You can explain what a function does
  • [ ] You know why writing shape(turtle) without quotes causes an error
  • [ ] You remember at least 3 of the 5 shape options

๐Ÿงฉ Key Takeaways

What you learned in this lesson:

Concept Description
shape() The function that sets the turtle shape
Quotes The shape name is 'turtle'quotes required, like this!
Option turtle, arrow, circle, square, triangle