+ 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

18th Aug 2024, 6:18 AM
Ziggy Ghost
Ziggy Ghost - avatar
3 Answers
+ 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)
18th Aug 2024, 10:32 AM
Melkon
Melkon - avatar
+ 5
Ziggy Ghost , see some explanations and a code sample to understand the `return` statement: https://sololearn.com/compiler-playground/c8w79FUr1j7u/?ref=app
18th Aug 2024, 6:26 AM
Lothar
Lothar - avatar
0
In Python, a return statement is used within a function to exit it and send back a value. When using essay writing services https://essaywriters.ae/, understanding how functions work is essential for automating repetitive tasks in programming.
3rd Sep 2024, 5:32 AM
Raida Maisa
Raida Maisa - avatar