Function Return Values: How Does Python Make Functions "Output" Results?

This article explains Python's function return value mechanism: return passes results back so functions can output values used by subsequent code, unlike print, which only displays them. 1. Why return matters: use return to return computed results, e.g. add(a,b) returns a+b, and the result can be assigned or used in calculations; without return, a function returns None and cannot be used in later operations (e.g. None*3 raises an error). 2. Return types and diversity: return values can be of many types (numbers, strings, lists, etc.), such as returning the string "Hello, Xiaoming" or the list [1,3,5]. 3. Multiple return values: separate multiple values with commas (essentially a tuple) and unpack them on call, e.g. name, age = get_user(); use _ to ignore unneeded values. 4. Function termination: return immediately stops the function, and subsequent code no longer runs. **Conclusion**: for a function to produce effective output, you must use return; otherwise it returns None and cannot pass results along or participate in computation.

Read More