Skip to content
All library documents

Python Function Returns, Nested Calls, and Price Alert Examples

PDF Quant course library

Summary

This lesson explains how Python functions return values and how that differs from printing output. It covers explicit returns, the implicit None result when no value is returned, how a return ends the current function, and how multiple returned elements are packaged as a tuple. It also groups functions by whether they accept parameters and return values, and distinguishes calling another function from defining a nested function.

Examples apply these ideas to a market-price alert: a helper retrieves a latest spot price, and a caller compares it with a threshold. A recursive example repeatedly checks a price, while the text cautions that excessive recursion can exhaust the call stack. These examples illustrate basic programming concepts rather than a trading strategy. The sample alert uses a hard-coded threshold and omits operational safeguards such as request failure handling, rate limits, and scheduling.

Key ideas

  • A function's return value can be assigned and used, while printed output is only displayed.
  • Functions without an executed return statement implicitly produce None.
  • A return statement ends that function call, and comma-separated returned values form a tuple.
  • Nested calls let one function use another function's result, as in a price alert.
  • Recursive price checks need a stopping condition to avoid excessive call depth.

Tags

From a private course collection; the original is not published.