Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python range() function
Next article icon

Python print() function

Last Updated : 10 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  • Object(s): It can be any python object(s) like string, list, tuple, etc. But before printing all objects get converted into strings.
  • sep: It is an optional parameter used to define the separation among different objects to be printed. By default an empty string(“”) is used as a separator.
  • end: It is an optional parameter used to set the string that is to be printed at the end. The default value for this is set as line feed(“\n”).
  • file: It is an optional parameter used when writing on or over a file. By default,, it is set to produce standard output as part of sys.stdout.
  • flush: It is an optional boolean parameter to set either a flushed or buffered output. If set True, it takes flushed else it takes buffered. By default, it is set to False.

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 = "[email protected]"
 
# print to stderr
print(Company, Location, Email, file=sys.stderr)
                      
                       

Output:

Geeksofrgeeks.org Noida [email protected]


Next Article
Python range() function

D

ddeevviissaavviittaa
Improve
Article Tags :
  • Python
  • Python-Built-in-functions
Practice Tags :
  • python

Similar Reads

  • hex() function in Python
    hex() function in Python is used to convert an integer to its hexadecimal equivalent. It takes an integer as input and returns a string representing the number in hexadecimal format, starting with "0x" to indicate that it's in base-16. Example: [GFGTABS] Python a = 255 res = hex(a) print(res) [/GFGT
    2 min read
  • id() function in Python
    In Python, id() function is a built-in function that returns the unique identifier of an object. The identifier is an integer, which represents the memory address of the object. The id() function is commonly used to check if two variables or objects refer to the same memory location. Python id() Fun
    3 min read
  • Python 3 - input() function
    In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string. Python input() Function SyntaxSyntax: input(prompt) Parameter: Prompt: (optio
    3 min read
  • Python int() Function
    The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part. Example: In this example, we passed a string as an argument to the int() function and printed it. [GFGTABS] Python age = "21"
    4 min read
  • Python len() Function
    The len() function in Python is used to get the number of items in an object. It is most commonly used with strings, lists, tuples, dictionaries and other iterable or container types. It returns an integer value representing the length or the number of elements. Example: [GFGTABS] Python s = "G
    2 min read
  • Python map() function
    The map() function is used to apply a given function to every item of an iterable, such as a list or tuple, and returns a map object (which is an iterator). Let's start with a simple example of using map() to convert a list of strings into a list of integers. [GFGTABS] Python s = ['1', '
    4 min read
  • Python - max() function
    Python max() function returns the largest item in an iterable or the largest of two or more arguments. It has two forms. max() function with objectsmax() function with iterablePython max() function With ObjectsUnlike the max() function of C/C++, the max() function in Python can take any type of obje
    4 min read
  • memoryview() in Python
    The memoryview() function in Python is used to create a memory view object that allows us to access and manipulate the internal data of an object without copying it. This is particularly useful for handling large datasets efficiently because it avoids the overhead of copying data. A memory view obje
    5 min read
  • Python min() Function
    Python min() function returns the smallest value from a set of values or the smallest item in an iterable passed as its parameter. It's useful when you need to quickly determine the minimum value from a group of numbers or objects. For example: [GFGTABS] Python a = [23,25,65,21,98] print(min(a)) b =
    4 min read
  • Python next() method
    Python's next() function returns the next item of an iterator. Example Let us see a few examples to see how the next() method in Python works. C/C++ Code l_iter = iter(l) print(next(l_iter)) Output1 Note: The .next() method was a method for iterating over a sequence in Python 2. It has been replaced
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences