파이썬/사용법
[Python] 문자열 메서드 요약표 – 상황별로 정리한 핵심 사용법
정성주의 기록
2025. 7. 22. 11:25
변환, 제거, 분리, 결합, 패턴 찾기, 교체, 판단
str.lower() 소문자로 변환
>>> text = "ABcDE"
>>> text.lower()
'abcde'
str.upper() 대문자로 변환
>>> text = "ABcDE"
>>> text.upper()
'ABCDE'
str. strip() 양 옆 원하는 단어 제거
>>> text = " aaaaa "
>>> text.strip()
'aaaaa'
str.split() 구분자를 기준으로 분리
>>> text = "aaa bbb ccc"
>>> text.split(" ")
['aaa', 'bbb', 'ccc']
str.join() 구분자 붙여서 결합
>>> text = ["aaa","bbb","ccc"]
>>> "--".join(text)
'aaa--bbb--ccc'
str.startwith() 접두사 패턴 검사
>>> text = "홍길동"
>>> text.startswith("홍")
True
>>> text.startswith("김")
False
str.endswith() 접미사 패턴 검사
>>> text = "홍길동"
>>> text.endswith("동")
True
>>> text.endswith("김")
False
str.replace() 단어 교체
>>> text = "홍길동"
>>> text.replace("홍","동")
'동길동'
str.find() 문자 찾기
>>> text = "동길동"
>>> text.find("동")
0
str.count() 텍스트 갯수 검사
>>> text = "동길동"
>>> text.count("동")
2
str.isalpha() 알파벳 판단
>>> text = "a"
>>> text.isalpha()
True
str.isspace() 공백 판단
>>> text = " "
>>> text.isspace()
True
str.isupper() 대문자 판단
>>> text = "A"
>>> text.isupper()
True
str.islower() 소문자 판단
>>> text = "a"
>>> text.islower()
True
str.isdigit() 숫자 판단
>>> text = "1"
>>> text.isdigit()
True