Holla Tech - Learn

Returning from Functions
 

Certain functions, such as int or str, return a value that can be used later.
To do this for your defined functions, you can use the return statement.

For example: 

def max(x, y):
    if x >=y:
        return x
    else:
        return y
       
print(max(4, 7))
z = max(8, 5)
print(z

 

Result: 

>>
7
8
>>> 

 

NOTE!
Technically, parameters are the variables in a function definition, and arguments are the values put into parameters when functions are called.

Returning from Functions
 

Once you return a value from a function, it immediately stops being executed. Any code after the return statement will never happen.
For example:

def add_numbers(x, y):
  total = x + y
  return total
  print(“This won’t be printed”)

print(add_numbers(4, 5)) 

 

Result: 

>>
9
>>> 

 


BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE PYTHON MAIN COURSE PAGE. 

PYTHON MAIN COURSE PAGE

 


©️ License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT