Course contentsShow
← Python
Lesson 50 of 1,0601. Foundations and EnvironmentFree lesson

Displaying Data Using the Print Function

Learners will be able to output strings, variables, and multiple data objects to the console using standard stream communication.

In this lesson, you will learn how to communicate with the outside world by sending information from your Python program to the console using the print function.

Communicating via the Console

Up until now, we have been working with data in the background, but to see our results, we need a way to output them. The print() function acts as a messenger: you provide it with data inside the parentheses, and Python displays that data on your screen.

Printing Strings and Variables

You can pass raw text (a string literal) directly into the function by wrapping it in quotes:

print("Hello, Python!")

If you have stored values in variables, you can pass the variable name instead. Python will look up the value associated with that name and display it for you:

score = 42
print(score)

Printing Multiple Objects

One of the most useful features of print() is its ability to handle multiple pieces of data at once. You can separate different items—like a string and a variable—using a comma. Python will automatically insert a space between these items when it prints them to the console:

user_name = "Alex"
level = 5
print("User", user_name, "is at level", level)

In this example, the output will appear as: User Alex is at level 5.

Because print() can accept any number of arguments separated by commas, it is a very flexible tool for debugging your code or showing the state of your variables during program execution. Whether you are printing the result of a calculation or a specific message, the print() function is your primary way to make your program's activity visible.

Key Takeaway: The print() function outputs data to the console, and you can display multiple items at once by separating them with commas, which Python will automatically space out for you.