Control Flow and Functions Flashcards
7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Control Flow and Functions flashcards as text
What is a default parameter value in Python?
Answer: A value used when no argument is provided for that parameter
Default parameter values let you call a function without providing that argument, using the defined default instead.
What is the output of the following? def f(x, y=2): return x * y print(f(3))
Answer: 6
With only one argument provided, `y` defaults to 2, so `f(3)` computes `3 * 2 = 6`.
Which statement about `break` in a nested loop is correct?
Answer: It exits only the innermost loop containing it
`break` only terminates the innermost loop in which it is placed; outer loops continue normally.
What is the output of the following code? for i in range(5): pass print(i)
Answer: 4
After the loop, `i` retains the last value assigned to it, which is 4 (range stops before 5).
Which of the following is a valid way to call a function using keyword arguments?
Answer: greet(name='Alice', age=30)
Keyword arguments use `param=value` syntax within the function call parentheses.
What happens if you use `else` with a `for` loop in Python?
Answer: It runs if the loop completes without hitting a `break`
The `else` clause of a `for` loop executes only if the loop finished normally without encountering a `break`.
What is the output of this code? def add(a, b): return a + b result = add(2, 3) print(result * 2)
Answer: 10
`add(2, 3)` returns 5, and `5 * 2` equals 10.