File I/O in Python
15 questions · 12 min · Medium
Test your knowledge of functions and lambda expressions in Python, including defining functions, parameters, arguments, return values, default arguments, keyword arguments, *args, **kwargs, scope, and lambda functions.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. def
The def keyword is used to define a function in Python.
A. return
The return statement exits the function and can provide a value to the caller.
A. def greet(name):
Python functions are defined using def followed by the function name and its parameters in parentheses.
A. A value passed to a function when it is called
An argument is a value supplied to a function when the function is called.
A. To provide a value when an argument is not supplied
A default parameter provides a predefined value that is used when the caller does not provide an argument for that parameter.
A. A variable number of positional arguments
The *args syntax collects additional positional arguments into a tuple.
A. A variable number of keyword arguments
The **kwargs syntax collects additional keyword arguments into a dictionary.
A. A function
A lambda expression creates a function object, typically used for short anonymous functions.
A. lambda x, y: x + y
Python lambda expressions use the lambda keyword, followed by parameters, a colon, and a single expression.
A. A lambda body contains a single expression
A lambda function consists of a parameter list and a single expression whose result is returned.
A. 7
The function adds the two numeric arguments, so 3 + 4 returns 7.
A. Local scope
A variable assigned inside a function is normally local to that function unless declared otherwise.
A. The function can be called using the * unpacking operator
The * operator can unpack an iterable into positional arguments when calling a function, such as func(*values).
A. To specify arguments by parameter name
Keyword arguments allow callers to associate values explicitly with parameter names, such as greet(name="Alex").
A. map()
The map() function applies a function, often a lambda, to each item of an iterable and returns a map iterator.