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 - Output Formatting
Next article icon

Python – Print Output using print() function

Last Updated : 02 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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: 

  • value(s): Any value, and as many as you like. Will be converted to a string before printed
  • sep=’separator’ : (Optional) Specify how to separate the objects, if there is more than one.Default :’ ‘
  • end=’end’: (Optional) Specify what to print at the end.Default : ‘\n’
  • file : (Optional) An object with a write method. Default :sys.stdout
  • flush : (Optional) A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False

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.

  • \n: This string literal is used to add a new blank line while printing a statement.
  • “”: An empty quote (“”) is used to print an empty line.

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="-") 

Output
12-12-2022

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()



Next Article
Python - Output Formatting

A

ABHISHEK TIWARI 13
Improve
Article Tags :
  • Python
  • python-basics
  • Python-Built-in-functions
  • Python-Output
  • Spotlight
Practice Tags :
  • python

Similar Reads

  • Python Tutorial | Learn Python Programming Language
    Python Tutorial – Python is one of the most popular programming languages. It’s simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. Python is: A high-level language, used in web development, data science, automat
    10 min read
  • Input and Output in Python
    Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is
    8 min read
  • Python basic I/O Techniques

    • Taking input in Python
      Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard. input ()
      3 min read
    • Python input() Function
      Python input() function is used to take user input. By default, it returns the user input in form of a string. input() Function Syntax:  input(prompt)prompt [optional]: any string value to display as input message Ex: input("What is your name? ") Returns: Return a string value as input by the user.
      4 min read
    • Taking input from console in Python
      What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks
      2 min read
    • Python - Print Output using print() function
      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. [GFGTABS] Python # print() function example print("GeeksforGeeks") a = [1, 2, 'gfg'] pri
      4 min read
    • Python - Output Formatting
      In Python, output formatting refers to the way data is presented when printed or logged. Proper formatting makes information more understandable and actionable. Python provides several ways to format strings effectively, ranging from old-style formatting to the newer f-string approach. Formatting Ou
      6 min read
    • Python3 I/O

      • Different Input and Output Techniques in Python3
        An article describing basic Input and output techniques that we use while coding in python. Input Techniques 1. Taking input using input() function -> this function by default takes string as input. Example: C/C++ Code #For string str = input() # For integers n = int(input()) # For floating or de
        3 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