Neural Sync Active
Functions
Registry Synced
Functions
102 words
1 min read
Functions
Functions package a small idea behind a name.
Contract
A function should have a clear contract:
- What inputs it accepts.
- What output it returns.
- What assumptions it makes.
pythondef double(x): return x * 2
The function receives
x, computes x * 2, and sends that result back to the caller.Return is not print
return gives a value back to the program. print shows a value to the human.pythonanswer = double(5) + 1
double(5) returns 10, so answer becomes 11.Practice
Write a one-sentence contract before coding a function.