โ† 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: ``` 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.

  2. Which of the following is NOT a valid use of sep= in Python 3?

    Answer: print('a', sep=1)

    `sep=` must be a string; passing an integer like `sep=1` raises a TypeError.

  3. What is the output of `print('2', '4', '6', sep='+', end='=?')`?

    Answer: 2+4+6=?

    sep='+' joins the three strings with '+', and end='=?' appends '=?' after the last item.

  4. What happens if you pass `end=None` to print()?

    Answer: It uses the default '\n' behavior

    Passing `end=None` explicitly resets the parameter to its default value of '\n', same as omitting end=.

  5. What is the output of: ``` print('hi', end='') print('there') ```

    Answer: hithere

    The first print emits 'hi' with no trailing newline, so 'there' from the second print follows immediately on the same line.

  6. What is the output of `print('cat', 'dog', sep=' and ')`?

    Answer: cat and dog

    The separator ' and ' is placed between the two string arguments, producing 'cat and dog'.

  7. If `sep=None` is passed to print(), what separator is actually used?

    Answer: A single space ' '

    Passing `sep=None` resets it to the default single space, identical to omitting the sep= argument entirely.