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.
Go deeper
Related to this question
About these practice questions
One of 169 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.