Defining and Calling Functions
Create functions with def and call them with arguments.
Defining and Calling Functions is a free Python Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Introduction
def Keyword
def greet(name):
print('Hello', name)
greet('Alice')Positional Arguments
def add(a, b):
return a + b
print(add(3, 4))Return Statement
def square(x):
return x * x
result = square(5)
print(result)Multiple Return Values
def min_max(lst):
return min(lst), max(lst)
lo, hi = min_max([3,1,4,1,5])
print(lo, hi)Docstrings
def greet(name):
"""Return a greeting string."""
return f"Hello {name}"
print(greet.__doc__)Variable Number of Arguments
def total(*nums):
return sum(nums)
print(total(1,2,3,4))Functions are Objects
def double(x): return x * 2
fn = double
print(fn(5))Calling with Unpacking
def add(a, b): return a + b
args = [3, 4]
print(add(*args))Lambda Functions
double = lambda x: x * 2
print(double(5))
print(list(map(lambda x: x**2, [1,2,3])))Nested Functions
def outer(x):
def inner(y):
return x + y
return inner
add5 = outer(5)
print(add5(3))Quick Check
Recap
Keep Going
Frequently asked questions
Is the “Defining and Calling Functions” lesson free?
Yes — the full text of “Defining and Calling Functions” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Defining and Calling Functions”?
Create functions with def and call them with arguments. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Defining and Calling Functions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Defining and Calling Functions
- Default and Keyword Arguments
- args and kwargs
- Return Values and Scope