+ 4
Return while defining a function?
So Iām a bit confused, in python; what exactly does the āreturnā command do? Because Iāve seen it in the lessons and used it but it never actually explains what it indeed does
2 Antwoorden
+ 6
The return statement is used inside a function to send a value back to the place where the function was called. Once a return statement is executed, the function ends, and the value specified by return is given back.
For example:
def add(a, b):
return a + b
result = add(5, 3) # The function returns 8, so result is 8
print(result)
+ 5
Ziggy Ghost ,
see some explanations and a code sample to understand the `return` statement:
https://sololearn.com/compiler-playground/c8w79FUr1j7u/?ref=app