Understanding the print() Statement in Python

print() Statement

If you’re just starting your Python journey, one of the very first lines of code you’ll encounter is:

greeting = 'Hello World!'
print(greeting)

It looks simple — and it is — but behind this simplicity lies one of the most fundamental tools you’ll use in Python: the print() statement.

Whether you’re debugging your code, displaying results to the user, or even learning how variables work, print() will accompany you throughout your entire journey.

In this article, we’ll break down what print() does, how it works, and why it’s so important for beginners.

What Exactly Is print()?

print() is a built-in Python function used to display output on the screen.

Whenever your program needs to show a message, value, or result, you call the print() function.

Think of it as Python’s way of talking back to you.

Breaking Down the Example

Here’s the code again:

greeting = 'Hello World!'
print(greeting)

Step 1: Creating a Variable

greeting = 'Hello World!'

Here you’re storing the text “Hello World!” in a variable named greeting.
A variable is simply a container that holds a value.

Step 2: Displaying the Value

print(greeting)

When we pass the variable greeting into print(), Python displays whatever is inside that variable.

Output:

Hello World!

Why Do We Use print()?

Here are the most common reasons:

1. To show results

When your program calculates something, you need a way to see what it did.

2. For debugging

If something isn’t working, print() can help you track what values your variables hold.

3. To communicate with the user

From simple text prompts to complex messages, print() helps your program talk to people.

Printing Different Types of Data

print() can display numbers, strings, lists, dictionaries, and more.

Numbers:

print(25)

Strings:

print("Python is awesome!")

Multiple values:

print("The total is:", 45 + 10)

Output:

The total is: 55

Printing Variables

Variables make print() even more useful:

name = "Sara"
age = 21
print(name, "is", age, "years old.")

Output:

Sara is 21 years old.

print() automatically separates values with spaces — which is great for readability.

Printing Without a New Line

By default, print() adds a new line after printing.

But you can change that behavior:

print("Hello", end=" ")
print("World!")

Output:

Hello World!

The end parameter lets you control what happens after each printed value.

Formatting Your Output

Python gives you many ways to format output.

f-Strings (recommended):

name = "Alex"
print(f"Hello, {name}!")

Output:

Hello, Alex!

format() method:

print("Hello, {}!".format(name))

Why print() Matters (More Than You Think)

As a beginner, print() may seem basic, but it teaches you:

  • how functions work
  • how data moves in a program
  • how variables store information
  • how to debug your own code
  • how to interact with users

Every Python programmer — even experts — uses print() daily.

Conclusion

The print() function is one of the simplest yet most powerful tools in Python. It’s your window into what your code is doing behind the scenes. Understanding how to use it properly will make your learning process smoother and much more enjoyable.

As you build larger projects, you’ll still find yourself coming back to this tiny but mighty function.

For more visite this repo

Happy coding!!


Understanding the print() Statement in Python was originally published in Javarevisited on Medium, where people are continuing the conversation by highlighting and responding to this story.

This post first appeared on Read More