Functions are reusable blocks of code that perform specific tasks. They help organize code, reduce redundancy, and improve readability. Here's a breakdown of key concepts:
📌 What is a Function?
A function consists of:
- Name (e.g.,
calculateSum
) - Parameters (inputs)
- Body (code logic)
- Return value (output)
def greet(name):
return f"Hello, {name}!"
🧩 How to Use Functions
- Define the function with
def
keyword - Call it using parentheses
- Pass arguments matching parameters
- Receive return values if needed
Example:
function add(a, b) {
return a + b;
}
console.log(add(3, 5)); // Output: 8
📚 Expand Your Knowledge
For deeper insights into programming basics, check our Introduction to Programming tutorial.
📷 Visual Examples
Functions are fundamental in any programming language. Master them to build efficient code! 💡