#functions
Functions
Functions let you package up a piece of logic, give it a name, and reuse it. They’re how you organize Python programs into manageable, testable pieces. In the Introduction to Python, we called built-in functions like print() and len(). Now let’s write our own. Defining Functions Use the def keyword: def greet(name): return f"Hello, {name}!" message = greet("Alice") print(message) # Hello, Alice! A function definition has: The def keyword A name (snake_case by convention) Parameters in parentheses A colon, then an indented body An optional return statement (returns None if omitted) Parameters and Arguments Positional arguments def add(a, b): return a + b print(add(3, 5)) # 8 Default values def greet(name, greeting="Hello"): return f"{greeting}, {name}! Read more →
May 18, 2026
Functions
Functions are the building blocks of JavaScript programs. They let you wrap up a piece of logic, give it a name, and reuse it whenever you need it. In the Introduction to JavaScript, we wrote a few simple functions. This tutorial goes much deeper — we’ll cover how JavaScript handles scope, what closures are, and how to use functions as values (higher-order functions). Function Declarations vs Expressions There are two main ways to define a function. Read more →
April 14, 2026