728x90
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 : " + url.split('.')[1])
print("split3 : " + url.split('.')[2])
# split1 : https://monkeycow
# split2 : tistory
# split3 : com/
3. 문자열 중에 가장 마지막 문자열 사용을 원할 경우
url = https://monkeycow.tistory.com/
print("last split : "+url.split('.')[-1])
# last split : com/
'selenium > 문자열' 카테고리의 다른 글
[Python] 문자열 대체 (0) | 2022.09.18 |
---|---|
[Python] 문자열 제거 (0) | 2022.09.17 |
[Python] 문자열 줄바꿈 기준으로 자르기 (splitline) (0) | 2022.09.16 |