Python Functions
Test your understanding with multiple-choice questions based on what you just learned.
Here is a beginner-friendly practice quiz based on the concepts covered on the "Tutorial on Python Functions":
Practice Quiz: Python Functions
Question 1: After writing a function what must you do to actually execute the code inside it? ) Write a new print statement B) Call a function by typing its name followed by parentheses C) Pack it into the tuple D) Wrap it in square brackets
Correct Answer: B Explanation: Writing a function is like writing a recipe; nothing happens until you actually "cook." To run the code, you must "call" function by typing its name with parentheses.
Question 2: According to the tutorial what's a primary benefit of using functions inside your code? A) They automatically sort numerical data. B) They permanently lock your data so it can't be changed. C) They save you from writing the same statements over and over again. D) They evaluate "truthy" and "falsy" logic faster.
Correct Answer: C Explanation: Functions allow you to reuse a block of code (like a print statement) hundreds of times simply by calling the function's name saving you out of writing the same code repeatedly.
Question 3: When you pass multiple inputs (like 5 10 15) into a function using *args, what data structure does Python magically pack them into?
A) dictionary
B) A string
C) A set
D) A tuple
Correct Answer: D
Explanation: The *args parameter collects multiple positional arguments and packs them safely into the tuple, allowing the function to work with all of them together.
Question 4: What does the abbreviation kwargs on **kwargs stand for?
A) Key arithmetic
B) Keyword arguments
C) Known variables
D) Kinetic words
Correct Answer: B
Explanation: The double asterisk ** is used for **kwargs which stands to "keyword arguments." It is used when you want to give your data specific names (like age=25 or city="Oslo") when passing it into the function.
Question 5: Into what highly optimized data structure does probably **kwargs collect its named data?
A) dictionary
B) tuple
C) A list
D) A set
Correct Answer: A
Explanation: Unlike *args which packs data into a tuple, **kwargs collects all about named keyword arguments into a highly optimized dictionary.