A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-output-using-print-function/ below:

Python - Print Output using print() function

Python - Print Output using print() function

Last Updated : 11 Jul, 2025

Python print() function prints the message to the screen or any other standard output device. In this article, we will cover about print() function in Python as well as it's various operations.

Python
# print() function example
print("GeeksforGeeks")

a = [1, 2, 'gfg']
print(a)
print() Function Syntax 

Syntax : print(value(s), sep= ' ', end = '\n', file=file, flush=flush)

Parameters: 

Return Type: It returns output to the screen.

Though it is not necessary to pass arguments in print() function, it requires an empty parenthesis at the end that tells Python to execute the function rather than calling it by name. Now, let's explore the optional arguments that can be used with the print() function.

In this example, we have 2 variables integer and string. We are printing all variables with print() function.

Python
name = "John"
age = 30

print("Name:", name)
print("Age:", age)

Output
Name: John
Age: 30
How print() works in Python?

You can pass variables, strings, numbers, or other data types as one or more parameters when using the print() function. Then, these parameters are represented as strings by their respective str() functions. To create a single output string, the transformed strings are concatenated with spaces between them.

If you want to master Python from start to finish, check out Boot.dev's Complete Python course here, we highly recommend it if you enjoy hands-on learning. The course stands out for its structured approach, interactive coding challenges, and focus on essential programming concepts. The best part is that you don't require any prior programming experience to complete the course.

In this code, we are passing two parameters name and age to the print function.

Python
name = "Alice"
age = 25

print("Hello, my name is", name, "and I am", age, "years old.")

Output
Hello, my name is Alice and I am 25 years old.
Python String Literals

String literals in Python's print statement are primarily used to format or design how a specific string appears when printed using the print() function.

This code uses \n to print the data to the new line.

Python
print("GeeksforGeeks \n is best for DSA Content.")

Output
GeeksforGeeks 
 is best for DSA Content.
Print Concatenated Strings with +

In this example, we are concatenating strings inside print() function.

Python
print('GeeksforGeeks is a Wonderful ' + 'Website.')
"end" parameter in print()

The end keyword is used to specify the content that is to be printed at the end of the execution of the print() function. By default, it is set to "\n", which leads to the change of line after the execution of print() statement.

Python
# without end parameter
print ("GeeksForGeeks is the best platform to learn Python")

# print() function ends with "**" as set in end parameter.
print ("GeeksForGeeks is the best platform to Learn Python", end= "**")
print("Welcome to GFG")
"sep" parameter in print()

The print() function can accept any number of positional arguments. To separate these positional arguments, the keyword argument "sep" is used.

This code is showing that how can we use sep argument for multiple variables.

Python
a = 12
b = 12
c = 2022
print(a, b, c, sep="-")

Note: As sep, end, flush, and file are keyword arguments their position does not change the result of the code. 

print() Function with file parameter

This code is writing the data in the print() function to the text file. 

Python
print('Welcome to GeeksforGeeks Python world.!!', file=open('Testfile.txt', 'w'))

Output

Python Print()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4