250x250
Link
๋์ GitHub Contribution ๊ทธ๋ํ
Loading data ...
Notice
Recent Posts
Recent Comments
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ๋น ๋ฐ์ดํฐ
- ๋ฐ์ดํฐ๋ถ๊ท ํ
- ADsP
- ๊ตฐ์งํ
- t-test
- ๋ ๋ฆฝํ๋ณธ
- ํ ์คํธ๋ถ์
- iloc
- datascience
- ํ์ด์ฌ
- ์ธ๋์ํ๋ง
- DBSCAN
- ์ค๋ฒ์ํ๋ง
- Python
- opencv
- ํฌ๋กค๋ง
- LDA
- pandas
- ์ฃผ์ฑ๋ถ๋ถ์
- ๋ฐ์ดํฐ๋ถ์
- dataframe
- ๋์ํ๋ณธ
- ๋น ๋ฐ์ดํฐ๋ถ์๊ธฐ์ฌ
- ADP
- numpy
- ๋ฐ์ดํฐ๋ถ์์ค์ ๋ฌธ๊ฐ
- ๋ฐ์ดํฐ๋ถ์์ ๋ฌธ๊ฐ
- ์๋ํด๋ผ์ฐ๋
- Lambda
- PCA
Archives
Data Science LAB
[Python] strip(), rstrip(), lstrip() ์ฌ์ฉ ๋ฐฉ๋ฒ ๋ฐ ์์ ๋ณธ๋ฌธ
๐ Python/๊ธฐ์ด
[Python] strip(), rstrip(), lstrip() ์ฌ์ฉ ๋ฐฉ๋ฒ ๋ฐ ์์
ใ ใ ใ ใ 2022. 10. 31. 00:00728x90
ํ์ด์ฌ์ strip()ํจ์๋ฅผ ์ด์ฉํ๋ฉด ๋ฌธ์์ ๊ณต๋ฐฑ์ ์์จ ์ ์๋ค.
- strip([chars]) :์ธ์๋ก ์ ๋ฌ๋ ๋ฌธ์๋ฅผ String์ ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์์ ์ ๊ฑฐ
- lstrip([chars]) : ์ธ์๋ก ์ ๋ฌ๋ ๋ฌธ์๋ฅผ String์ ์ผ์ชฝ์์ ์ ๊ฑฐ
- rstrip([chars]) : ์ธ์๋ก ์ ๋ฌ๋ ๋ฌธ์๋ฅผ String์ ์ค๋ฅธ์ชฝ์์ ์ ๊ฑฐ
1. ๊ณต๋ฐฑ ์ ๊ฑฐ
: strip() ํจ์ ์์ ์๋ฌด ์ธ์๋ ์ ๋ฌํ์ง ์์ผ๋ฉด ๊ณต๋ฐฑ์ ์ ๊ฑฐํจ
text = ' Water boils at 100 degrees '
print('[' + text.rstrip() + ']')
print('[' + text.lstrip() + ']')
print('[' + text.strip() + ']')
# result
[ Water boils at 100 degrees]
[Water boils at 100 degrees ]
[Water boils at 100 degrees]
2. ๋์ผํ ๋ฌธ์ ์ ๊ฑฐ
: ์ธ์๋ก ๋ฌธ์ ํ๋๋ฅผ ์ ๋ฌํ๋ฉด ๋์ผํ์ง ์์ ๋ฌธ์๊ฐ ๋์ฌ๋ ๊น์ง ์ ๊ฑฐํจ
text = '0000000Water boils at 100 degrees 000'
print(text.lstrip('0'))
print(text.rstrip('0'))
print(text.strip('0'))
# result
Water boils at 100 degrees 000
0000000Water boils at 100 degrees
Water boils at 100 degrees
3. ์ฌ๋ฌ ๋ฌธ์ ์ ๊ฑฐ
: ์ธ์๋ก ์ฌ๋ฌ ๋ฌธ์๋ฅผ ์ ๊ฑฐํ ๊ฒฝ์ฐ์๋ ๋์ผํ์ง ์์ ๋ฌธ์๊ฐ ๋์ฌ ๋ ๊น์ง ์ ๊ฑฐํจ
text = ",,,,,123.....water....pp"
print(text.lstrip(',123.p'))
print(text.rstrip(',123.p'))
print(text.strip(',123.p'))
# result
water....pp
,,,,,123.....water
water
728x90
'๐ Python > ๊ธฐ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ์ ๊ท ํํ์์ ์์ฃผ ์ฌ์ฉ๋๋ ๋ฌธ์ ๋ชจ์ (0) | 2022.11.07 |
---|---|
[Python] ์ ์ฌ ๋์ ๋๋ฆฌ defaultdict() (0) | 2022.11.04 |
[Python] ์์ ์ฐพ๊ธฐ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ(Prime Number) (0) | 2022.10.30 |
[Python] ๋ฌธ์์ด์์ ์ซ์ ์ถ์ถ (0) | 2022.10.28 |
[Python] ์์์ ์ฒ๋ฆฌ 4๊ฐ์ง ๋ฐฉ๋ฒ (0) | 2022.10.20 |
Comments