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:
Difference between Yield and Return in Python
Next article icon

Difference between return and print in Python

Last Updated : 05 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, we may use the print statements to display the final output of a code on the console, whereas the return statement returns a final value of a function execution which may be used further in the code. In this article, we will learn about Python return and print statements.

Return Statement in Python

Python return statement is used to exit the function and return a value. The return keyword is used to specify a value that a function should return when a function is called. It performs some calculations or operations and then returns the value or a set of values to the calling code.

Syntax of Return Statement

def function_name(parameters):      # The function body      return value

Example:

In this example, we can see that when the 'add_number' function is called, it returns the sum of 'a' and 'b', which is stored in the result variable. Then using the print statement, the result is printed on the console.

Python3
def add_numbers(a, b):     return a + b  result = add_numbers(7, 9) print(result) 

Output:

16

Print Statement in Python

The print statement is a built-in function in Python that is used to display output to the console or terminal.

Syntax of Print Statement

print(*objects, sep=' separator', end='\n', file=sys.stdout, flush=False)

Example:

In this example, we can see that the 'greet' function does not return any value but simply prints the value using the print statement when it is called.

Python3
def greet(name):     print("Hello, %s!" % name)  greet("ABC") 

Output:

Hello, ABC!

Difference between Return and Print Statement in Python

Let us see the difference between the Python return and Python Print statement.

Return Statement

Print Statement

It is used to exit a function and return a valueIt is used to display output to the console
It returns a value that can be assigned to a variable or used in any expressionIt displays output to the console but does not return the value
It can be used multiple times in a function but only one value can be returned at a timeIt can be used multiple times in a function but does not affect the function's return value
Exiting the function with return ends the function and control returns to calling codeThe print does not affect program flow and execution continues normally
Example: return sum in a function that calculates the sum of two numbersExample: print("Hello, world!") to display a message on the console

Next Article
Difference between Yield and Return in Python

S

subramanyasmgm
Improve
Article Tags :
  • Python
Practice Tags :
  • python

Similar Reads

  • Difference between + and , Python Print
    In this article, we will learn about the difference between + and, in Python print, The print() function in Python is used to print some messages as the output on the screen. We can print a single element or even multiple elements on the screen. Python provides two ways to print multiple elements as
    3 min read
  • Difference between Yield and Return in Python
    Python Yield It is generally used to convert a regular Python function into a generator. A generator is a special function in Python that returns a generator object to the caller. Since it stores the local variable states, hence overhead of memory allocation is controlled. Example: # Python3 code to
    2 min read
  • Difference between end and sep in Python
    In this article we will discuss the difference between The end and sep are two parameters in Python's built-in print() function that will help to control how the output is formatted. end in PythonThe end is a parameter in Python's built-in print() function that controls what character(s) are printed
    2 min read
  • Difference between Logging and Print in Python
    In Python, print and logging can be used for displaying information, but they serve different purposes. In this article, we will learn what is python logging with some examples and differences between logging and print in Python. Logging in Python Logging in Python is a technique to display useful m
    3 min read
  • Difference between %s and %d in Python string
    In this article, we will see the difference between %s and %d in Python. Here, we start with the proper explanation of one at a time, then both, and at last compare these. What does %s do in Python? The % symbol is used in Python with a large variety of data types and configurations. It is used as a
    3 min read
  • Difference between == and is operator in Python
    In Python, == and is operators are both used for comparison but they serve different purposes. The == operator checks for equality of values which means it evaluates whether the values of two objects are the same. On the other hand, is operator checks for identity, meaning it determines whether two
    4 min read
  • Python: Difference between dir() and help()
    In Python, the dir() and help() functions help programmers understand objects and their functionality. dir() lists all the attributes and methods available for an object, making it easy to explore what it can do.help() provides detailed information about an object, including descriptions of its meth
    5 min read
  • Python - Difference between := and ==
    In this article, we will be discussing the major differences between Walrus(:=) and the Comparison operator (==) := in PythonThe := operator in Python, also known as the walrus operator or assignment expression, was introduced in Python 3.8. It enables assignment and evaluation to happen simultaneou
    2 min read
  • Difference Between Del, Remove and Pop in Python Lists
    del is a keyword and remove(), and pop() are in-built methods in Python. The purpose of these three is the same but the behavior is different. remove() method deletes values or objects from the list using value and del and pop() deletes values or objects from the list using an index. del Statementde
    2 min read
  • Difference between / vs. // operator in Python
    In Python, both / and // are used for division, but they behave quite differently. Let's dive into what they do and how they differ with simple examples. / Operator (True Division)The / operator performs true division.It always returns a floating-point number (even if the result is a whole number).I
    2 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