A RetroSearch Logo

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

Search Query:

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

Python print() function - GeeksforGeeks

Python print() function

Last Updated : 10 Jan, 2023

The python print() function as the name suggests is used to print a python object(s) in Python as standard output.

Syntax: print(object(s), sep, end, file, flush)

Parameters:

Example 1: Printing python objects Python3
# sample python objects
list = [1,2,3]
tuple = ("A","B")
string = "Geeksforgeeks"

# printing the objects
print(list,tuple,string)

Output:

[1, 2, 3] ('A', 'B') Geeksforgeeks
Example 2: Printing objects with a separator Python3
# sample python objects
list = [1,2,3]
tuple = ("A","B")
string = "Geeksforgeeks"

# printing the objects
print(list,tuple,string, sep="<<..>>")

Output:

[1, 2, 3]<<..>>('A', 'B')<<..>>Geeksforgeeks
Example 3: Specifying the string to be printed at the end Python3
# sample python objects
list = [1,2,3]
tuple = ("A","B")
string = "Geeksforgeeks"

# printing the objects
print(list,tuple,string, end="<<..>>")

Output:

[1, 2, 3] ('A', 'B') Geeksforgeeks<<..>>
Example 4: Printing and Reading contents of an external file

For this, we will also be using the Python open() function and then print its contents. We already have the following text file saved in our system with the name geeksforgeeks.txt.

To read and print this content we will use the below code:

Python3
# open and read the file
 my_file = open("geeksforgeeks.txt","r")
  
# print the contents of the file
print(my_file.read())

Output:

Example 5: Printing to sys.stderr Python3
# Python code for printing to stderr

# importing the package
# for sys.stderr
import sys 

# variables
Company = "Geeksforgeeks.org"
Location = "Noida"
Email = "contact@geeksforgeeks.org"

# print to stderr
print(Company, Location, Email, file=sys.stderr)

Output:

Geeksofrgeeks.org Noida contact@geeksforgeeks.org


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