Python
Your first function
A practical reference with examples you can run.
Introduction
A function packages a useful operation under a name. Parameters supply input, and a return value carries the result back to the caller. Keep printing separate from calculation so you can reuse and test the function.
Syntax & example
def double(number):
return number * 2
print(double(7))Expected output
14
Common mistakes
- Using a variable before assigning a value to it.
- Mixing text and numbers without converting deliberately.
- Skipping an empty input or a boundary value when testing.
Practice
Write a function that doubles its input.
main.pyYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-84 lines