# Why doesn't str.strip work as I expect?

**URL:** https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257
**Category:** Python Help
**Created:** [September 27, 2026, 9:04pm UTC](https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257 "2026-09-27T21:04:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tjreedy](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tjreedy/32/137_2.png) [@tjreedy](https://discuss.python.org/u/tjreedy)
#### Post date: [September 27, 2026, 9:04pm UTC](https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257/1 "2026-09-27T21:04:43Z")

</div>

A beginner who should have asked this here, opened a tracker issue thinking that ` " ##Python## ".lstrip(' #')` should produce "Python## ". In other words, that lstrip always deletes leading whitespace and that the optional chars argument adds to whitespace instead of replacing default whitespace. I repeat below an edited version my answer there.

* * *

Use interactive help() to get the answer below.

```python
>>> help(str.lstrip)
Help on method descriptor lstrip:

lstrip(self, chars=None, /) unbound builtins.str method
    Return a copy of the string with leading whitespace removed.

    If chars is given and not None, remove characters in chars instead.

```

Pass `''.lstrip` instead and the first line will instead say “built-in function lstrip”.

The ending, “remove characters in chars instead.” suggests trying

```python
>>> " ##Python## ".lstrip(' #')
'Python## '

```

which indeed works as desired.

If one enters `s.lstrip(` in IDLE, and waits for a calltip, it is just the two lines

```python
lstrip(self, chars=None, /)
Return a copy of the string with leading whitespace removed.

```

which is slightly misleading, but It serves as a reminder of the default and that lstrip only works on the left. Hopefully, one who does not know what non-default `chars` does will ask `help` or ask here on Python Discourse.

---

<div class="post-metadata">

### Author: ![Stefan2](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/stefan2/32/18492_2.png) [@Stefan2](https://discuss.python.org/u/Stefan2)
#### Post date: [September 27, 2026, 9:18pm UTC](https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257/2 "2026-09-27T21:18:02Z")

</div>

> [@tjreedy](#):
>
> thinking that `" ##Python## ".lstrip(' #')` should produce "Python## ".

It _does_ produce that.

---

<div class="post-metadata">

### Author: ![elis.byberi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/elis.byberi/32/35937_2.png) [@elis.byberi](https://discuss.python.org/u/elis.byberi)
#### Post date: [September 27, 2026, 10:09pm UTC](https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257/3 "2026-09-27T22:09:20Z")

</div>

There is a typo. Actually, it is:

```python
p=" ##Python## "
print(p.lstrip("#"))

```

---

<div class="post-metadata">

### Author: ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)
#### Post date: [September 27, 2026, 10:24pm UTC](https://discuss.python.org/t/why-doesnt-str-strip-work-as-i-expect/109257/4 "2026-09-27T22:24:57Z")

</div>

`lstrip` removes the characters from the string at the left end (treating it like a set), if any appear. `"#"` doesn’t appear at the left edge of the string, so no deletion occurs.

Also, to avoid transcription errors in the future, it’s best to copy and paste from an actual interactive session, like so:

```python
$ python
Python 3.13.5 (main, Aug 10 2026, 12:06:59) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> " ##Python## ".lstrip('#')
' ##Python## '
>>> " ##Python## ".lstrip(' #')
'Python## '
>>>

```

Edit: full details https://docs.python.org/3/builtins/stdtypes.html#str.lstrip.
