Beginner ยท ages 8+ ยท print ยท variables ยท strings
Hello world and variables in Python.
Print a message, store things in variables and join them together.
The program
Press Run to see what it prints. Change anything you like, then run it again.
name = "Asha"
age = 10
print("Hello, " + name + "!")
print("Next year you will be", age + 1)
print(name, "is learning Python")
print(name * 3)Hello, Asha! Next year you will be 11 Asha is learning Python AshaAshaAsha
How it works
- A variable is a name for a value.
nameholds text (a string) andageholds a number. printshows things on the screen. Strings can be joined with+, and a comma prints several things with a space between.- Multiplying a string by a number repeats it:
name * 3prints the name three times.
Try this
- Change
nameandageto your own. - Add a line that prints the age next year in a sentence.
- What happens if you write
age + "1"? Python will give an error: numbers and strings do not mix.
Stuck on an error? Read how to debug Python.
Similar ideas
More programs
FAQ
Hello world and variables: questions
What does the hello world and variables program do?
Print a message, store things in variables and join them together. It prints: Hello, Asha! / Next year you will be 11 / Asha is learning Python โฆ
Which Python ideas does it use?
print, variables, strings. Beginner level, suitable from about age 8.
How do I run it?
Press Run on this page. To run it on your own computer, install Python 3 and save the code in a file ending in .py. It prints the same thing.
What should I try next?
Change name and age to your own. Add a line that prints the age next year in a sentence. What happens if you write age + "1"? Python will give an error: numbers and strings do not mix.
Start a conversation
Want a teacher to guide the learning?
Tell us the learner's age and what they can already do, and we will suggest a starting point. A parent or guardian can make the enquiry.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay