-
[string] 문자열 자주 쓰이는 문법 정리🐍 파이썬/파이썬 기본 문법 2022. 7. 17. 06:42
String indexing
String formatting
String method
1.대소문자 변환
.upper(), .lower() 메소드 (비파괴적 함수)
a = "hello" a.upper()
2. 공백제거
.strip(), lstrip(), rstrip()
a = " hello " a.strip()
3.구성
# moethods result boolean s = "some string..." s.startswith("some") # Bool: True s.endswith("!") # Bool: False "xxx" in s # Bool: False "1".isdigit() # Bool: True "e".isupper () # Bool: False "r".islower () # Bool: True
4. 문자열 찾기
.find() : 왼쪽부터 탐색을 시작해서 처음 키워드가 등장하는 인덱스를 반환
.rfind() : 오른쪽부터 탐색을 시작해서 처음 키워드가 등장하는 인덱스를 반환
5. 문자열 split
결과로 리스트가 반환된다
'🐍 파이썬 > 파이썬 기본 문법' 카테고리의 다른 글
함수를 함수의 변수로 넘기기 (0) 2022.07.18 [Function] 함수란 (0) 2022.07.18 working with file (0) 2022.07.17 False in Python (0) 2022.07.17 isinstance(x,y) (0) 2022.07.17