Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Print vs Return | What is a Function?
Python Functions: From Zero to Hero

book
Print vs Return

print() is a function called by a person. If you want to show the value to a person then you need to use the function print ().

return is the Python keyword. When the program reaches the return keyword, Python stops the current function and sends the resulting value to where the function was called.

def function():
a = 5
b = 2
c = a + b
return c

result = function()
print(result)
12345678
def function(): a = 5 b = 2 c = a + b return c result = function() print(result)
copy
Uppgift

Swipe to start coding

You need to implement a function named function_adding. This function should calculate the sum of the next three numbers, such as a=5, b=455, c=23, store the result in a variable sum and return it.

Lösning

def function_adding():
a = 5
b = 455
c = 23
sum = a + b + c
return sum

result = function_adding()
print(result)

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 5
# Write your code below




# Testing
result = function_adding()
print(result)

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt