return statement
The statement return expression, which ends a function call immediately and hands the value back to the caller.
In more detail
The caller can then store, print or compute with the value, as in total = sumList(nums). Printing is not returning: a function that only prints hands back None. A return inside a loop stops both the loop and the function.
Example
def square(x):
return x * xRelated terms
- function — A named, reusable block of code that takes inputs, called arguments, and can return a result.
- None value — Python's special value meaning nothing here, which is what a function returns if it has no return statement.
- function call — Running a function by writing its name followed by parentheses holding any arguments.
Taught in
- Returning Values — Hands-on Python: Complete Video Course & Book
- Dictionaries — Hands-on Python: Complete Video Course & Book
- Accumulation Loops — Hands-on Python: Complete Video Course & Book
- Chapter One In One Sitting — Hands-on Python: Complete Video Course & Book
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Methods And The self Parameter — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep