Python String Manipulation and Formatting Flashcards
6 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Python String Manipulation and Formatting flashcards as text
Which escape sequence represents a newline in a Python string?
Answer: \n
\n is the newline escape sequence that inserts a line break in a string.
What does a raw string like `r'\n'` contain?
Answer: A backslash followed by the letter n
The r prefix disables escape processing, so r'\n' is literally backslash + n, not a newline.
How do you repeat a string 3 times in Python?
Answer: 'ab' * 3
The * operator with an integer repeats a string that many times: 'ab' * 3 == 'ababab'.
What is the output of `' hello '.strip()`?
Answer: 'hello'
strip() removes all leading and trailing whitespace characters, returning 'hello'.
Which method checks if all characters in a string are digits?
Answer: isdigit()
isdigit() returns True if every character in the string is a decimal digit (0–9).
What does `'hello'.center(11, '*')` return?
Answer: '***hello***'
center() pads the string to the specified total width by placing fill characters equally on both sides.