Python Output

6 min read ·

What is Output in Python?

Output is the information that a program displays to the user after executing the instructions. In Python, output can be text, numbers, variables, calculation results, or messages displayed on the screen.
The most commonly used function for displaying output is the print() function.
Whenever you want to show something to the user, you use the print() function.
Note

The print() function is one of Python's built in functions. It is used to display output on the screen.


Python print() Function

The syntax of the print() function is very simple.
The value written inside the parentheses is called an argument. It can be text, a number, a variable, or even the result of an expression.

Printing Text

Text is written inside quotation marks. Python then displays that text exactly as it is.

Output

You can print any message you want.

Output


Printing Multiple Lines

You can call the print() function as many times as needed. Each print() statement displays its output on a new line.

Output

Python automatically moves the cursor to the next line after every print() statement.
Real World Scenario

Suppose you are creating a student report card application. You may want to display the student's name, roll number, and marks on separate lines. Using multiple print() statements makes the output clean and readable.


Using Single Quotes and Double Quotes

Python allows you to write text using either single quotes (' ') or double quotes (" ").
Using double quotes
Using single quotes

Output

Both examples produce the same output. You can choose either style, but it is a good practice to remain consistent throughout your program.
Pro Tip

Most Python developers prefer double quotes for strings because they improve readability, but both single and double quotes are equally valid.


What Happens if Quotes are Missing?

Python treats text without quotation marks as a variable or identifier.
Consider the following example.
Python looks for a variable named Hello. Since no such variable exists, it produces an error.

Output

To print text correctly, always place it inside quotation marks.
Correct example
Caution

Whenever you want to display text, always enclose it in either single quotes or double quotes.


Printing Numbers

Numbers do not require quotation marks because they are numeric values.

Output

Python prints integers and floating point numbers directly.

Printing Variables

The print() function can also display the value stored inside a variable.

Output

Instead of printing the variable name, Python prints the value stored inside it.

Printing Expressions

The print() function can display the result of mathematical expressions.

Output

Python first evaluates the expression and then prints the result.

Printing Multiple Values

You can print multiple values in a single print() statement by separating them with commas.

Output

By default, Python inserts a space between each value.

Using the sep Parameter

The sep parameter changes the separator between multiple values.

Output

You can use any separator such as a comma, dash, colon, or arrow.
Another example

Output


Using the end Parameter

By default, every print() statement ends with a new line.

Output

You can change this behavior using the end parameter.

Output

Another example

Output

The end parameter replaces the default newline character with the value you provide.
Real World Scenario

The end parameter is useful when displaying progress messages, menus, or formatted output where multiple values should appear on the same line.


Common Mistakes

Forgetting Quotation Marks

Incorrect code
Correct code

Forgetting Parentheses

Incorrect code
Correct code
Python 3 requires parentheses with every print() function call.

Missing Closing Quote

Incorrect code
Correct code
Python cannot determine where the string ends if the closing quotation mark is missing.
Stop

Always check that every opening quotation mark has a matching closing quotation mark.


Best Practices

Write meaningful output messages.
Use consistent quotation marks throughout your program.
Print variables instead of hardcoding values whenever possible.
Use the sep parameter to format multiple values clearly.
Use the end parameter only when you intentionally want output on the same line.
Keep output clean and easy to read.
Great Job

You have learned how to display output in Python using the print() function. You also know how to print text, numbers, variables, expressions, multiple values, and how to customize the output using the sep and end parameters.


Exercise

1.Print your name.
2.Print your city and country using two separate print() statements.
3.Print three programming languages in a single print() statement.
4.Print your name and age using variables.
5.Print the result of 25 + 15.
6.Print "Python", "Java", and "C++" separated by " | ".
7.Print "Hello" and "World" on the same line using the end parameter.

Challenge

Write a Python program that displays the following output.