Lesson 32 of 55
8 mins readPython Return Values & Modern Subroutine Signatures
In Plain English
Perl subroutines return the value of an explicit `return` statement, or automatically return the last evaluated expression in the block.
Deep Dive: How It Works
Explicit return: Immediately exits the subroutine with the specified value or list.
Implicit Return: If `return` is omitted, the result of the final statement is returned.
Returning Lists: Subroutines can return multiple values: `return ($min, $max);`.
Core Rules to Remember

Explicit return: Provides clear readability and early exit capability.

Multiple Returns: Returns lists that can be unpacked directly into variables.
Live Interactive Example
Hit Run Code to see it liveMultiple Return Values
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
Output Console
Click "Run Code" to view the rendered output.
How it works: min_max returned a two-element list unpacked into ($lowest, $highest).
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Return Status and Code
Define `sub get_response { return (200, "OK"); }`.
Unpack `my ($code, $msg) = get_response();` and print `"Response: $code $msg\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.