Functions in Python
A function is a reusable block that does one job. You write it once with def, then call it. square(5) should return 25 — not only print it, if the caller needs the number.
Shape: def square(n): return n * n. Colon, indented body. Call: print(square(5)). Output 25. Without return, the function gives None. Freshers print inside and wonder why x = square(5) is None.
Defaults: def greet(name="Guest"). Call greet() or greet("Asha"). Keep one job per function. Name it after what it does: total_marks, not do_stuff.
Let’s do it on the board. def square(n): return n * n. print(square(5)) → 25. Change to square(6) in your head → 36. That dry-run is the example.
Functions in Python — output — 25. square(5) returns 25. Change to square(6) → 36.
def square(n):
return n * n
│ square(5)
▼
25Explain return vs no return.