Python return statement
The Python return statement is used to return a value from a function. The user can only use the return statement in a function. It cannot be used outside of the Python function. A return statement includes the return keyword and the value that will be returned after that.
Syntax of return statement:
Returning Multiple Values
In the Python programming language, a user can return multiple values from a function. The following are the various methods for this.
2. Using Tuple: The tuple is similar to a list, but there is a slight difference between tuple and list. In the tuple, the object values cannot be changed, while the object value can be changed in the list.
3. Using list: The list is similar to the dynamically sized array. In the list, the user can store everything in a single variable.
4. Using dictionary: In the Python language, a dictionary is a collection of unstructured items that are used to store data values such as hash or map.
5. Using Data Class (Python 3.7+)
Function returning another function
In the Python programming language, a function is in the form of an object. Therefore, the user can return a function from another function.
In the below program, The first_add function returns the second_add function.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week