---
title: "str.strip"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/strings/strip"
updated: "2026-10-05"
---

Removes spaces (or other characters) from both ends of a string.

## Synopsis

```python
text.strip()
text.strip(characters)
```

## Description

Users often type a stray space before or after an answer. `strip` removes spaces, tabs and new lines from the start and end.

`lstrip` removes from the left end only, and `rstrip` from the right end only.

## Parameters

| Name | Meaning |
| --- | --- |
| `characters` | Which characters to remove. Optional. The default is any whitespace. |

## Return value

A new `str`.

## Example

```python
name = "  Ada  "
print(f"[{name}]")
print(f"[{name.strip()}]")
print("--hi--".strip("-"))
```

It prints:

```text
[  Ada  ]
[Ada]
hi
```

## Common mistake

```python
print("a b c".strip())
```

It prints:

```text
a b c
```

`strip` only touches the two ends. To remove every space, use `replace(" ", "")`.

## See also

[str.replace](/student-handbook/python-manual/strings/replace), [str.lower](/student-handbook/python-manual/strings/lower), [str.split](/student-handbook/python-manual/strings/split)

[str.strip in the Python documentation](https://docs.python.org/3/library/stdtypes.html#str.strip)
