본문으로 바로가기

[Python] 문자열 제거

category selenium/문자열 2022. 9. 17. 14:28
728x90

1. 공백 제거

test= "   Hello World   "

print("lstrip :[" + test.lstrip()+"]")
print("rstrip :[" + test.rstrip()+"]")
print("strip :[" + test.strip()="]")

# lstrip :[Hello World  ] 
# rstrip :[   Hello World]  
# strip :[Hello World]

2. 특정 문자 제거

test= www.test.com.www

print("lstrip :[" + test.lstrip('w')+"]")
print("rstrip :[" + test.rstrip('w')+"]")
print("strip :[" + test.strip('w')="]")

# lstrip :[.test.com.www] 
# rstrip :[www.test.com]  
# strip :[.test.com]