โ† All PCEP Flashcard Decks

Using `sep=` and `end=` in `print()` 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 Using `sep=` and `end=` in `print()` flashcards as text
  1. What is the output of `print('a', 'b', 'c', sep='-')`?

    Answer: a-b-c

    The `sep='-'` argument places a hyphen between each argument passed to print.

  2. What does `print('Hello', end='')` do differently than `print('Hello')`?

    Answer: Suppresses the trailing newline

    By default `end='\n'`, so passing `end=''` removes the newline that would follow the output.

  3. What is printed by: ``` print(1, 2, 3, sep=', ', end='!') ```

    Answer: 1, 2, 3!

    `sep=', '` joins the numbers with comma-space, and `end='!'` replaces the newline with `!`.

  4. Which call produces the output `Hello World` (no newline at the end)?

    Answer: Both A and C

    Both `print('Hello World', end='')` and `print('Hello', 'World', end='')` suppress the newline (the latter also uses default `sep=' '`).

  5. What is the output of: ``` for i in range(3): print(i, end=' ') ```

    Answer: 0 1 2

    Each iteration prints the number followed by a space instead of a newline, resulting in `0 1 2 ` with a trailing space.

  6. What is the output of `print('x', 'y', sep='', end='\n')`?

    Answer: xy

    `sep=''` places nothing between 'x' and 'y', producing 'xy', and `end='\n'` is the default so a newline follows.

  7. What happens when you call `print(sep='|')` with no positional arguments?

    Answer: Prints an empty line

    With no positional arguments, there are no items to separate, so only the `end` value (default newline) is printed, producing a blank line.