What are Python functions and how do you define them?
Why Interviewers Ask This
This is a classic screening question for Python roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
Functions in Python are defined with the def keyword: def greet(name, greeting="Hello"): return f"{greeting}, {name}!". Functions support default parameter values, making parameters optional. Python supports positional and keyword arguments: greet("Alice") or greet(greeting="Hi", name="Alice"). *args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. Functions are first-class objects in Python — they can be assigned to variables, passed as arguments, and returned from other functions. Functions without a return statement implicitly return None. Use docstrings to document functions: """This function greets a person.""" as the first statement.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Python codebase.