ob-vaults/Phoenix/Python/remove space in text in python.md
2024-09-12 17:54:01 +03:30

51 lines
770 B
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

status: #doc
Tags: #python #programming
links: [[python]] [[python/text]]
Date: 2023-05-01
___
# remove space in text in python
we use [strip()](https://www.w3schools.com/python/ref_string_strip.asp) for it , its a **[value-returning function]** so remember to store the value
## remove just space
in default state [strip()](https://www.w3schools.com/python/ref_string_strip.asp) just remove space before and after words for example
```python
txt = "     banana     "
x = txt.strip()
print("of all fruits", x, "is my favorite")
```
## remove other characters
### syntax
```
string.strip(characters)
```
- example
```python
txt = ",,,,,rrttgg.....banana....rrr"
x = txt.strip(",.grt")
print(x)
```
---
# References