Mixed Deck — All PCEP Topics Flashcards
100 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 20 Mixed Deck — All PCEP Topics flashcards as text
What is the output of the following? x = 5 def change(): x = 10 change() print(x)
Answer: 5
Without the `global` keyword, `x = 10` inside `change()` creates a local variable, leaving the global `x` unchanged at 5.
What is the output of `print('Python', 3, sep='.')`?
Answer: Python.3
sep='.' is placed between the string 'Python' and the integer 3 after it is converted to its string representation.
Which of the following will raise an `IndexError`?
Answer: my_list = [1, 2]; my_list[5]
Accessing `my_list[5]` on a list with only 2 elements raises `IndexError` because the index is out of the valid range.
What is the output of: ```python for i in range(3): pass print(i) ```
Answer: 2
The loop variable `i` retains its last value after the loop ends, which is 2 for `range(3)`.
What is the output of `[0] * 4`?
Answer: [0, 0, 0, 0]
Multiplying a list by an integer repeats its elements that many times.
What is the result of: ``` print('A', end='B') print('C') ```
Answer: ABC
The first print ends with 'B' instead of '\n', so 'C' from the second print immediately follows, producing 'ABC' on one line.
What is the output of: ``` for ch in 'abc': print(ch, end='-') ```
Answer: a-b-c-
Each character is printed with a trailing '-' instead of a newline, producing 'a-b-c-' including a trailing hyphen.
What is printed by the following code? for i in range(10): if i % 2 == 0: continue if i > 6: break print(i)
Answer: 1 3 5
Odd numbers are printed; `continue` skips evens and `break` stops when i exceeds 6, so 7 never prints.
What will `print(True, False, sep=' or ')` output?
Answer: True or False
Boolean values are converted to their string representations 'True' and 'False', with ' or ' placed between them.
What does `my_dict.get('missing', 0)` return if `'missing'` is not in `my_dict`?
Answer: 0
The `get()` method returns the default value (second argument) when the key is absent.
What does `'apple,banana,cherry'.split(',')` return?
Answer: ['apple', 'banana', 'cherry']
`split(',')` breaks the string at each comma and returns a list of the resulting substrings.
What is the correct way to raise a ValueError with a custom message?
Answer: raise ValueError('message')
Exceptions are raised by calling them like a class constructor: `raise ValueError('message')` creates an instance and raises it.
What is the output of the following? def greet(name, msg='Hello'): print(msg, name) greet('Bob') greet('Alice', 'Hi')
Answer: Hello Bob\nHi Alice
First call uses the default msg='Hello' with name='Bob'; second call overrides msg with 'Hi' and name='Alice'.
Which of the following has the LOWEST precedence in Python?
Answer: or
Among logical operators and comparisons, `or` has the lowest precedence, evaluated last.
What is the output of `float('3.14')`?
Answer: 3.14
`float()` converts a string representation of a decimal number to a float value.
What is a `SyntaxError` in Python?
Answer: An error detected by the parser when code violates Python grammar rules
`SyntaxError` is raised by the Python parser when the source code does not conform to Python's grammar, before execution begins.
What is the output of `print('Python'[1])`?
Answer: y
String indexing starts at 0, so index 1 returns the second character `'y'`.
What is the output of: ``` print('row1', end='\n') print('row2', end='\n') ```
Answer: row1\nrow2\n
Both lines explicitly set `end='\n'`, which is the default behavior, so each prints on its own line.
What does round(3.567, 1) return in Python?
Answer: 3.6
round(3.567, 1) rounds to 1 decimal place; since the second decimal is 6 (≥5), it rounds up to 3.6.
Which loop is guaranteed to execute its body at least once?
Answer: None — Python has no do-while, so neither guarantees one execution
Python does not have a do-while loop, so neither `for` nor `while` guarantees at least one execution; the condition is checked before the first iteration.