본문으로 바로가기

[Python] 문자열 대체

category selenium/문자열 2022. 9. 18. 14:34
728x90

1. 공백 삭제

text = "Hello World Bye"

print(text.replace(" ", ""))

# HelloWorldBye

2. 특정 문자로 변환

text = "a.monkeycow.tistory.com"

print(text.replace("a", "www"))

# www.monkeycow.tistory.com