← All Python Flashcard Decks

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

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

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

  4. What is the output of `' hello '.strip()`?

    Answer: 'hello'

    strip() removes all leading and trailing whitespace characters, returning 'hello'.

  5. 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).

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