Variables & strings · About 7 minutes

A backpack for your ideas

The big little idea

A variable gives a name to a value so you can use it again. Think of a labeled pocket in your adventure backpack: the label stays, but you can swap what is inside.

pet = "dragon"
name = "Noodle"
print(f"My {pet} is called {name}.")

The = symbol assigns a value. An f-string starts with f before the quotes and lets you insert variables inside {curly braces}. Variable names are case-sensitive: pet and Pet are different.

Predict, then try: read the example from top to bottom. What do you think it will print? Copy it into the editor below to test your prediction.

Your turn, code explorer.

Create a pet called Pickle. Print My robot is called Pickle. using the variables below.

My robot is called Pickle.
my_adventure.pyPython · in your browser

Edit the code. Then run it. Ctrl / ⌘ + Enter also works.

OutputYOUR IDEAS, ALIVE
Your program’s output will appear here.

Ready when you are. ✦

The first run loads Python. This can take a moment.

Program input For programs that use input()

Add answers before you run. Each input() reads the next line. Use made-up names and details.

Real Python, powered by Pyodide. Standard-library programs work here; desktop windows, turtle graphics, and package installation are not supported by this editor. Programs stop after 10 seconds of execution.

Back to the starting code?

This replaces your edits for this activity. Download your code first if you want to keep it.

A little hint, please

Change only the value stored in name. Keep the quotation marks.

Show one possible solution

There can be more than one way. Read this version, then try writing it yourself.

pet = "robot"
name = "Pickle"
print(f"My {pet} is called {name}.")
Pack this idea for later: Variables help one program work with many different values.