โ† 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 method removes leading and trailing whitespace from a string?

    Answer: strip()

    strip() removes whitespace (or specified characters) from both ends of a string.

  2. What does `'hello'.upper()` return?

    Answer: 'HELLO'

    upper() returns a new string with all characters converted to uppercase.

  3. What is the output of `'Python'.replace('P', 'J')`?

    Answer: 'Jython'

    replace() substitutes all occurrences of the first argument with the second, giving 'Jython'.

  4. What does `'a,b,c'.split(',')` return?

    Answer: ['a','b','c']

    split() divides a string on the given separator and returns a list of substrings.

  5. Which f-string expression correctly formats a float to 2 decimal places?

    Answer: f'{value:.2f}'

    The format spec :.2f means fixed-point notation with 2 digits after the decimal.

  6. What does `'hello world'.title()` return?

    Answer: 'Hello World'

    title() capitalizes the first letter of every word and lowercases the rest.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy