Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
return

What is the Python return statement?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

A return statement comprises of the return keyword followed by the value that will be returned.​

def test_func():
a = 10 + 1
return a
print(test_func());

Every function in Python returns something. A function without a return statement returns None. Something similar can be said about functions that contain a return statement ​but no return value​.

def test_func(): #Function without return statement
a = 10
b = 4
c = a + b
def test_func2(): #Function without return value
a = 10
return
print(test_func())
print(test_func2())

Contrary to languages like C and C++, Python return statements can return more than one value.

def test_func():
a = 10 + 1
b = "eleven"
return a, b
x, y = test_func()
print(x)
print(y)

RELATED TAGS

python
return
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring