[Python]String Method
5588 단어 pythonstring methodStringString

📌String
- 문자들의 나열
- Immutable
- Ordered
- Iterable
📌String Method
.find(x)
- 문자열 조회/탐색
x의 첫 번째 위치를 반환, 없으면 -1 반환
'water'.find('b') # -1
'useless'.find('s') # 1
.index(x)
x의 첫 번째 위치를 반환, 없으면 오류 발생
'useless'.index('s') # 1
'useless'.index('a') #ValueError
.replace(old, new[, count])
old를 new로 바꿔서 반환
count를 지정하면 해당 개수만큼 시행
'useless'.replace('s', 'a') #uaeleaa
'useless'.replace('s', 'a', 2) #uaeleas
.strip([chars])
- 특정 문자
chars 지정하면, 메소드에 따라 해당 방향에서 제거
- 문자열 지정하지 않으면 공백 제거
.strip() 양쪽, .lstrip() 왼쪽, .rstrip() 오른쪽
' hello '.strip() #hello
' hello '.rstrip() # hello
' hello '.lstrip() #hello
.split([chars])
- 문자열을 특정한 단위로 나눠 리스트로 반환
'a b c'.split() #['a', 'b', 'c']
'seperator'.join([iterable])
iterable 컨테이너 요소들을 seperator로 합쳐 문자열 반환
"-".join(['a', 'b', 'c']) #'a-b-c'
.capitalize() 첫 글자를 대문자, 나머지 소문자
'heLLo'.capitalize() #Hello
.title() ' 또는 공백 이후의 첫 문자를 대문자
"heLLo, it's mE".title() #"Hello, It'S Me"
.upper() 모두 대문자
.lower() 모두 소문자
.swapcase() 대문자 <-> 소문자 변경
.isalpha() 알파벳 문자 여부
- 유니코드 기준이므로, 한글도 True를 반환
.isupper() 대문자 여부
.islower() 소문자 여부
.istitle() 타이틀 형식여부
.isdecimal(), .isdigit(), .isnumeric()
- 숫자 여부, 상황에 따라 판단하는 것이 다름
Author And Source
이 문제에 관하여([Python]String Method), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@mein-figur/PythonString-Method
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
.find(x)- 문자열 조회/탐색
x의 첫 번째 위치를 반환, 없으면 -1 반환
'water'.find('b') # -1
'useless'.find('s') # 1.index(x)x의 첫 번째 위치를 반환, 없으면 오류 발생
'useless'.index('s') # 1
'useless'.index('a') #ValueError.replace(old, new[, count])old를new로 바꿔서 반환count를 지정하면 해당 개수만큼 시행
'useless'.replace('s', 'a') #uaeleaa
'useless'.replace('s', 'a', 2) #uaeleas.strip([chars])- 특정 문자
chars지정하면, 메소드에 따라 해당 방향에서 제거 - 문자열 지정하지 않으면 공백 제거
.strip()양쪽,.lstrip()왼쪽,.rstrip()오른쪽
' hello '.strip() #hello
' hello '.rstrip() # hello
' hello '.lstrip() #hello .split([chars])- 문자열을 특정한 단위로 나눠 리스트로 반환
'a b c'.split() #['a', 'b', 'c']'seperator'.join([iterable])iterable컨테이너 요소들을seperator로 합쳐 문자열 반환
"-".join(['a', 'b', 'c']) #'a-b-c'.capitalize() 첫 글자를 대문자, 나머지 소문자'heLLo'.capitalize() #Hello.title() ' 또는 공백 이후의 첫 문자를 대문자"heLLo, it's mE".title() #"Hello, It'S Me".upper() 모두 대문자.lower() 모두 소문자.swapcase() 대문자 <-> 소문자 변경.isalpha() 알파벳 문자 여부- 유니코드 기준이므로, 한글도 True를 반환
.isupper() 대문자 여부.islower() 소문자 여부.istitle() 타이틀 형식여부.isdecimal(), .isdigit(), .isnumeric() - 숫자 여부, 상황에 따라 판단하는 것이 다름
Author And Source
이 문제에 관하여([Python]String Method), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@mein-figur/PythonString-Method저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)