Python for beginners · Lesson 1 of 15

Your first Python program

Meet Python, write your first line of code with print(), run it right in the page and leave notes with comments.

About 10 minutes · code runs in your browser, nothing to install

Python is a programming language: a way to write instructions that a computer can follow. It reads almost like English, which makes it one of the easiest languages to start with, and it is used for websites, data analysis, automation, science and games.

You do not need to install anything for this course. Every code box on this site runs real Python inside your browser. Press Run to see what the code prints, then change it and run it again. You cannot break anything.

Your first line of code

Pythoneditable
print("Hello, world!")
Output
Hello, world!

print() shows whatever you put between its round brackets. Text must be wrapped in quotes, either "double" or 'single'. A piece of text in quotes is called a string.

Several lines, numbers and sums

A program is a list of instructions. Python runs them one by one, from the top line to the bottom line. Numbers do not need quotes, and Python works out a sum before printing it.

Pythoneditable
print("Hello, world!")
print("I am learning Python.")
print(7)
print(2 + 3)
print("2 + 3")
Output
Hello, world!
I am learning Python.
7
5
2 + 3

The last line is in quotes, so it is printed as text, not calculated.

You can give print() several values separated by commas. It puts one space between them. An empty print() prints a blank line.

Pythoneditable
print("Price:", 12, "euros")
print()
print("Total:", 12 + 8, "euros")
Output
Price: 12 euros

Total: 20 euros

Comments: notes for humans

Everything after a # sign on a line is a comment. Python skips it completely. Comments explain what the code does, to other people and to you in a few weeks. You can also put # in front of a line to switch it off without deleting it.

Pythoneditable
# This program greets a visitor.
# Python skips every line that starts with #.
print("Welcome to Pythonversity!")  # a comment can also end a line
# print("This line does not run")
Output
Welcome to Pythonversity!
Watch out: Python is picky about spelling. Print("hi") with a capital P does not work, and neither does print("hi') with mismatched quotes. If you get an error, compare your line letter by letter with the example.

✎ Exercise

Write a program that prints three lines: your name, the city you live in, and what you want to build with Python. Use one print() per line.

Hint: Each line needs its own print() with the text in quotes. Your text will differ from the solution, and that is fine.

Your codewrite your answer, then Run
# your code here

Expected output:

My name is Lena.
I live in Vienna.
I want to build a budget app.
Show a solution
Solutioneditable
print("My name is Lena.")
print("I live in Vienna.")
print("I want to build a budget app.")
Output
My name is Lena.
I live in Vienna.
I want to build a budget app.

Check yourself

1. What does print("4 + 4") show?

2. Which line is a comment?

3. What does print("Hi", "there") show?

Spotted a mistake on this page? Tell us