[Python] 문자열 대체 1. 공백 삭제 text = "Hello World Bye" print(text.replace(" ", "")) # HelloWorldBye 2. 특정 문자로 변환 text = "a.monkeycow.tistory.com" print(text.replace("a", "www")) # www.monkeycow.tistory.com selenium/문자열 2022. 9. 18. 14:34
[Python] 문자열 제거 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.. selenium/문자열 2022. 9. 17. 14:28
[Python] 문자열 줄바꿈 기준으로 자르기 (splitline) Hello World Bye 라는 문장이 있을 경우 print("splitline1 : "+text.splitline()[0]) print("splitline2 : "+text.splitline()[1]) print("splitline3 : "+text.splitline()[2]) # splitline1 : Hello # splitline2 : World # splitline3 : Bye 마지막 리스트 사용을 원할 경우 print("last splitline : "+text.splitline()[-1]) # last split : Bye selenium/문자열 2022. 9. 16. 21:32
[Python] 문자열 자르기 (split) 1. 띄어쓰기 기준으로 문자열 자르기 test_string="Hello World!" test_string.split() 띄어쓰기 기준으로 잘라서 리스트화 시킴 print("split1 : "+test_string.split()[0]) print("split2 : "+test_string.split()[1]) # split1 : Hello # split2 : World 2. 특정 문자로 자름 url = https://monkeycow.tistory.com/ url.split('.') 이면 .을 기준으로 문자열을 잘라서 리스트화 시킴 # url = https://monkeycow.tistory.com/ print("split1 : " + url.split('.')[0]) print("split2 : " +.. selenium/문자열 2022. 9. 16. 21:19