Skip to content
dreamcode
dreamcode
Map
Helper functions
Lesson 25 of 77
+15 XP on finish
PYTHON BASICSChapter 4 · Functions

Combining functions

Great programs are built from tiny, reusable blocks. You can call functions from inside other functions, passing the output of one function as the input to another.

Worked example

How it reads

  • add_stars(5) returns 15
  • format_sky(total) takes 15 and returns "Sky with 15 stars"
Cloud tip: Writing small helper functions makes your code much easier to read, test, and debug.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add a helper square(n) and print square(double(3)), which is 36.

Press Run to check your work.