Python Tutorial Python Advanced Python References Python Libraries

Python return Keyword



The Python return keyword is used to exit from a function and return a value.

Example:

In the example below, return keyword is used to return the square of a given number.

def area_square(a):
  area = a * a
  print("Area of the square is:")
  return area

print(area_square(3))

The output of the above code will be:

Area of the square is:
9

Any statement after return statement is ignored by the program.

Example:

In the example below, the print statement after return statement is ignored when executed.

def area_square(a):
  area = a * a
  return area
  print("Area of the square is:")

print(area_square(3))

The output of the above code will be:

9

❮ Python Keywords