Select Page

ABIOLA RASP – Raspberries for African School Projects

Wie können wir helfen?

< Alle Themen
Print

Python – Functions with return value

no-169 au-03

return Keyword

Functions return a value with return keyword and you can use function return value for different purpose.

Please see the article “Python – First Program” how to open Thonny Python IDE and how to save your work.

  1. Define a function: multiply(x, y)
  2. It returns the result of x*y
  3. Define a function: sum(x, y)
  4. The result of  x+y is assigned to result
  5. It returns the value of result
  6. Print the result of 5*8
  7. It assigns the result of 5+8, so a = 13
  8. Print a
  9. Here is the result

Code:
def multiply(x, y):     
return x*y 

def sum(x, y):     
result = x + y    return
result

print(multiply(5, 8))

a = sum(5 ,8)
print(a)

Inhaltsverzeichnis