Courseiva
Question 261 of 169
StringsmediumMultiple SelectObjective-mapped

Remove Leading Whitespace from String — lstrip() and strip()

Which TWO of the following can be used to remove leading whitespace (spaces, tabs, newlines) from a string? (Choose exactly 2 correct answers.)

Quick Answer

The correct answers are lstrip() and strip(), as both can remove leading whitespace from a string. The lstrip() method is specifically designed to strip only leading characters—spaces, tabs, and newlines—from the left side of a string, while strip() removes whitespace from both the beginning and the end, which necessarily includes the leading portion. On the Certified Associate Python Programmer PCAP exam, this question tests your precise understanding of Python’s string methods and their directional behavior; a common trap is confusing rstrip() (which removes trailing whitespace) with lstrip(), or assuming a generic trim() or clean() method exists in Python. To remember, think of the letter L in lstrip() as standing for “left” or “leading,” and strip() as the all-in-one cleaner that handles both ends.

⚠ Common exam trap

Candidates often confuse `rstrip()` with removing leading whitespace because of the 'r' prefix, or incorrectly assume `trim()` or `clean()` are valid Python methods.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

lstrip()

The `lstrip()` method removes all leading whitespace characters (spaces, tabs, newlines) from the left side of a string. `strip()` removes leading and trailing whitespace, so it also satisfies the requirement of removing leading whitespace. Both are built-in string methods in Python.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • rstrip()

    Why it's wrong here

    rstrip() removes trailing whitespace only.

  • lstrip()

    Why this is correct

    lstrip() specifically removes leading whitespace.

  • trim()

    Why it's wrong here

    trim() is not a method in Python strings.

  • clean()

    Why it's wrong here

    clean() is not a method in Python strings.

  • strip()

    Why this is correct

    strip() removes both leading and trailing whitespace, so it effectively removes leading whitespace as well.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on PCAP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which two methods can be used to remove leading whitespace from a string? (Choose two.)

medium
  • A.s.strip()
  • B.s.lstrip()
  • C.s.split()
  • D.s.chomp()
  • E.s.rstrip()

Why A: `s.strip()` removes both leading and trailing whitespace from the string, including spaces, tabs, and newline characters. This method is commonly used when you need to clean up a string entirely, but it does more than just leading whitespace removal.

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.