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
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 print three items on the same line separated by tabs?
Answer: Both A and C
Both using `sep='\t'` and embedding `\t` directly in one string produce tab-separated output on one line.
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 default value of the `sep=` parameter in Python's `print()` function?
Answer: A single space ' '
The default separator is a single space, which is why `print('a', 'b')` outputs `a b`.
What does the following print? ``` print(*[1, 2, 3], sep='-') ```
Answer: 1-2-3
The `*` unpacks the list into three separate arguments, and `sep='-'` places a hyphen between each of them.
Which statement correctly describes `end=` in `print()`?
Answer: It sets the string appended after all arguments are printed
`end=` controls the string that is appended after all positional arguments have been printed, defaulting to '\n'.
What is the output of: ``` print('1', '2', sep='0', end='0') ```
Answer: 1020
sep='0' places a '0' between '1' and '2' giving '102', then end='0' appends another '0' giving '1020'.