โ† 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('hello', end='\t', sep=',')`?

    Answer: hello

    With only one argument, sep= has no effect; end='\t' replaces the default newline with a tab character.

  2. How can you print the values 10, 20, 30 all on one line with no separator?

    Answer: print(10, 20, 30, sep='')

    Setting `sep=''` removes any character between the printed values so they appear concatenated as '102030'.

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

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

  5. Which two parameters together let you print items on a single line with custom spacing and no trailing newline?

    Answer: sep= and end=

    `sep=` controls spacing between items and `end=''` (or any non-newline) prevents moving to the next line.

  6. What is the output of: ``` print('a', 'b', sep='\n') ```

    Answer: a\nb

    Using `sep='\n'` places a newline character between 'a' and 'b', so they appear on separate lines.

  7. What is the output of: ``` print('X', 'Y', 'Z', sep='*', end='*') ```

    Answer: X*Y*Z*

    sep='*' places '*' between each argument giving 'X*Y*Z', and end='*' appends one more '*' at the very end.