• Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Mock Interview Series
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials
      • InfyTQ Archive
      • Infosys Archive
      • TCS Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
      • Java Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Mock Interview Series
    • Register
    • Login
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Mock Interview Series
  • Register
  • Login

Cart

return Statement in Python with Example

  • November 27, 2021
  • CODE OF GEEKS
  • 0


The return Statement in Python is used to return a value from a particular function (method) and hence used to end the execution of a program. We can return values from a function to the calling function with the help of return keyword in Python.

Syntax

return x

In the above syntax, variable ‘x’ is returned to the calling function. Variable ‘x’ can be an integer, string, boolean, list, tuple or anything.

return 

In the above syntax, the return statement is without any expression, in this case, a special value called None is returned.

Returning Results from a Function

return x # returns value of x
return 1 # returns 100
return lst # returns list
return x, y, z # returns 3 values


Do you know ?

The None keyword is used to define a null value. None is not the same as 0, false, or an empty string.

Program : To code a function that returns the multiplication of two integers.

# function to return the multiplication of two numbers

def multiply(a, b):
    mul = a * b
    # now since we have calculated the result we just need to return this value back
    return mul

# calling the multiply() function and printing the result

result = multiply(3, 5)
print("Multiplication of the numbers is : ", result)
click to zoom


#facts_about_return_statement

  1. In Python, return is treated as a keyword.
  2. In Python, we can return multiple values in the form of int, float, str, list, tuple, set, dictionary etc.
  3. In Python, we can even return a function itself.
  4. return statement should be used inside function/ method.
  5. return statement can be inside if-else statements as well.
  6. return statement can also include expression, in such cases expression is first evaluated then returned.
  7. A function can not return values two times within a same function. In such cases, one first return statement is entertained, while the second one is ignored.

That’s all about return statement in Python.





Tags: can we return more than one value in pythonpython return statementreturn pythonreturn statement in pythonreturn statement python
  • Previous Introduction to Functions in Python with Example
  • Next assert Statement in Python with Example

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Content – Python

  1. Introduction to Python Programming
    • Python and its features
    • Key Differences : C vs Python
    • Key Differences : Java vs Python
    • Python Flavors
    • PVM and Memory Management in Python

  2. Python Programming Fundamentals
    • 'Hello World' using Python
    • Comments in Python
    • Variables and Garbage Collection in Python
    • Datatypes in Python
    • Determining the Datatype of Literal | type() method
    • Tokens in Python
    • Keywords in Python
    • Identifiers and Naming Convention in Python
    • Literals in Python

  3. Python Operators
    • Operators in Python
    • Python Mathematical Functions

  4. Python User Inputs
    • Taking Inputs | input() function in Python

  5. Python Control Statements
    • Control Statements in Python
    • if-elif-else Statements in Python
    • Looping in Python
    • while loop in Python
    • while-else loop in Python
    • for loop in Python
    • for-else loop in Python
    • Infinite loops in Python
    • Nested loops in Python
    • break Statement in Python
    • continue Statement in Python
    • pass Statement in Python
    • assert Statement in Python
    • return Statement in Python

  6. Python Functions
    • Introduction to Python Functions
    • Python Functions vs Python Methods
    • Local and Global Variables in Python
    • Formal and Actual Arguments in Python
    • Recursion in Python Functions
    • Lambda Functions in Python
    • Function Decorators in Python
    • Function Generators in Python
CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

Strings in Python and Operations on Python Strings
  • January 18, 2022
Hedger
  • January 15, 2022

Copyright 2022 CODE OF GEEKS. All Rights Reserved.

  • →