51 lines
770 B
Markdown
51 lines
770 B
Markdown
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
|
||
|
||
|
||
|