← All PCEP Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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)`.

  5. What is the output of `[0] * 4`?

    Answer: [0, 0, 0, 0]

    Multiplying a list by an integer repeats its elements that many times.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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'.

  14. Which of the following has the LOWEST precedence in Python?

    Answer: or

    Among logical operators and comparisons, `or` has the lowest precedence, evaluated last.

  15. What is the output of `float('3.14')`?

    Answer: 3.14

    `float()` converts a string representation of a decimal number to a float value.

  16. 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.

  17. What is the output of `print('Python'[1])`?

    Answer: y

    String indexing starts at 0, so index 1 returns the second character `'y'`.

  18. 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.

  19. 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.

  20. 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.