Algorithm/Python

[파이썬] startswith(), endswith() / 특정 문자열 찾기

say! 2022. 8. 6. 16:13
728x90

startswith() : 특정 문자열로 시작하는지 True/False 반환

endswith() : 특정 문자열로 끝나는지 True/False 반환

 

- Hi로 시작하는 문장 수 세기

if line.startswith('Hi'):
	count = count + 1

문자열.startswith(찾을 문자열, 검사 시작 위치, 검사 끝 위치)

문자열.endswith(찾을 문자열, 검사 시작 위치, 검사 끝 위치)

시작위치, 끝 위치 생략가능