Concept Flow - Methods with return values
Define method
Call method
Execute method body
Return value
Receive returned value
Use returned value
This flow shows how a method is defined, called, executes, returns a value, and how that value is used.
def add(a, b): return a + b result = add(3, 4) print(result)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Define method 'add' | Store function with parameters a, b | Method ready to call |
| 2 | Call add(3, 4) | Parameters a=3, b=4 | Enter method body |
| 3 | Calculate a + b | 3 + 4 | 7 |
| 4 | Return 7 | Return value sent back | Method call replaced by 7 |
| 5 | Assign result = 7 | Store 7 in variable 'result' | result = 7 |
| 6 | Print result | Output value of result | 7 |
| 7 | End | No more code | Program stops |
| Variable | Start | After Step 4 | After Step 5 | Final |
|---|---|---|---|---|
| a | N/A | 3 | 3 | 3 |
| b | N/A | 4 | 4 | 4 |
| result | Undefined | Undefined | 7 | 7 |
def method_name(params):
return value
- 'return' sends value back to caller
- Caller can store or use returned value
- Without return, method returns None
- Use returned value to continue program logic