Printing

Welcome to the Python course! Python is one of the most widely used programming languages in the world: people use it to build websites, analyze data, work with artificial intelligence and automate everyday tasks. Its code is short and reads almost like English, which makes it a great first language.

A program is a series of commands that the computer carries out one after another, from top to bottom. Your first command will show something on the screen. A program often calculates things that nobody can see, so printing the results is how you find out what it did and whether it works.

To print something in Python, write print() and put what you want to print inside the parentheses:

print(4)
print("Hello, world!")

This prints:

4
Hello, world!

What a program prints appears in the output: here, it's the black panel on the right (on a phone, under Output). Each print() prints on a new line, and the program runs them in the order in which they are written. A print() with nothing in the parentheses prints an empty line.

Notice three things:

  • Text goes in quotes, numbers don't. The quotes show Python where the text starts and ends, so that it doesn't try to read the words as commands. You can use double quotes "Hello" or single quotes 'Hello'; in this course, we use double quotes. Numbers are written without quotes: 4.
  • print is written in lowercase. Python treats uppercase and lowercase letters as different, so Print("Hello") ends with an error.
  • Every opening parenthesis needs a closing one, and every opening quote needs a closing quote.

print is a function: a command with a name, which you use by writing the name followed by parentheses. Inside the parentheses goes what the function should work with. You'll meet more functions soon.

If something in your program is wrong, Python stops and shows a red error message below the output. Don't worry about it: check the quotes and parentheses, and run the program again. Later in this lesson, you'll learn to read these messages.

Instructions

In the editor on the right, print your age with print(). It's a number, so write it without quotes. Then click Run below the editor. The first run takes a few seconds, while Python loads.

On the next line, print your name. It's text, so put it in quotes.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/15