Recently, I have been revisiting Solidity, consolidating the finer details, and writing "WTF Solidity" tutorials for newbies.
Twitter: @0xAA_Science | @WTFAcademy_
Community: Discord|Wechat|Website wtf.academy
Codes and tutorials are open source on GitHub: github.com/AmazingAng/WTF-Solidity
In this chapter, we will introduce the Solidity function output, including returning multiple values, named returns, and reading full or part of return values using destructuring assignments.
Return values (return and returns)
There are two keywords related to function output: return and returns:
returnsis added after the function name to declare variable type and variable name;returnis used in the function body and returns desired variables.
In the above code, the returnMultiple() function has multiple outputs: returns (uint256, bool, uint256[3] memory) , and then we specify the return variables/values in the function body with return (1, true, [uint256 (1), 2,5]) .
Named returns
We can indicate the name of the return variables in returns, so that solidity automatically initializes these variables, and automatically returns the values of these functions without adding the return keyword.
In the above code, we declare the return variable type and variable name with returns (uint256 _number, bool _bool, uint256[3] memory _array) . Thus, we only need to assign values to the variable _number, _bool and _arrayin the function body, and they will automatically return.
Of course, you can also return variables with return keyword in named returns:
Destructuring assignments
Solidity internally allows tuple types, i.e. a list of objects of potentially different types whose number is a constant at compile-time. The tuples can be used to return multiple values at the same time.
- Variables declared with type and assigned from the returned tuple, not all elements have to be specified (but the number must match):
- Assign part of return values: Components can be left out. In the following code, we only assign the return value
_bool2, but not_ numberand_array:
Verify on Remix
- Deploy the contract, and check the return values of the functions.

Summary
In this section, we introduced function return values return and returns, including returning multiple variables, named returns, and reading full or part of return values using destructuring assignments.