Exercise: Python

Questions for: Functions

What is the purpose of the isinstance() function?
A:
Checks if a variable is of a certain type
B:
Determines if an object is callable as a function
C:
Reverses the order of elements in a list
D:
Converts a string to uppercase
Answer: A
The isinstance() function is used to check if a variable is of a certain type.
What is the purpose of the sum() function?
A:
Computes the sum of elements in an iterable
B:
Checks if a variable is of a certain type
C:
Converts a list to uppercase
D:
Sorts elements of a list in ascending order
Answer: A
The sum() function is used to compute the sum of elements in an iterable, such as a list.
What does the term "lambda function" refer to?
A:
A function with a lengthy definition
B:
A function defined using the def keyword
C:
A function with a single line of code
D:
A function that calls itself
Answer: C
A lambda function in Python is a concise way to define a function with a single line of code.
What is the purpose of the callable() function?
A:
Checks if a variable is of a certain type
B:
Determines if an object is callable as a function
C:
Converts a string to uppercase
D:
Creates a new list with specified values
Answer: B
The callable() function checks if an object can be called as a function.
How do you define a variable with a global scope inside a function?
A:
Using the global keyword
B:
Using the local keyword
C:
Using the global_scope() function
D:
Using the global_variable parameter
Answer: A
The global keyword is used to declare a variable with a global scope inside a function.
Ad Slot (Above Pagination)
Quiz