← 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. How do you check if a string starts with a specific prefix in Python?

    Answer: str.startswith('py')

    startswith() returns True if the string begins with the specified prefix.

  2. What is the result of `''.join(['a','b','c'])`?

    Answer: 'abc'

    join() concatenates list elements using the calling string as separator; an empty string means no separator.

  3. What does `'Python'[1:4]` evaluate to?

    Answer: 'yth'

    Slicing [1:4] returns characters at indices 1, 2, and 3, which are 'y', 't', 'h' → 'yth'.

  4. Which method returns the index of the first occurrence of a substring, or -1 if not found?

    Answer: find()

    find() returns the lowest index where the substring is found, or -1 if absent; index() raises ValueError instead.

  5. What does the format string `'{0} {1}'.format('Hello', 'World')` produce?

    Answer: 'Hello World'

    Positional placeholders {0} and {1} are replaced with the first and second format arguments.

  6. What is the output of `len('hello world')`?

    Answer: 11

    The string 'hello world' has 5 + 1 space + 5 = 11 characters.