AboutPython
[파이썬] 파이썬 특정 문자 찾기 ( find, startwith, endwith )
scone
2022. 6. 16. 00:08
[find]
- find( 찾을 문자, 찾기 시작하는 위치 )
>>> s = 'abcde fghijklmnj'
>>> s.find('j')
10
>>> s.find('j',10)
10
>>> s.find('j',11)
15
>>> s.find('z')
-1
[startswith]
- startswith( "문자" 로 시작하는지, 시작지점 )
>>> s = 'abcde fghijklmnj'
>>> s.startswith('a')
True
>>> s.startswith('a',1)
False
>>> s.startswith('c',2)
True
[endswith]
- endwith('문자'로 끝나는지, 탐색을 시작하는 인덱스, 탐색이 끝나는 인덱스)
>>> s = 'abcde fghijklmnj'
>>> s.endswith('nj')
True
>>> s.endswith('mj')
False
>>> s.endswith('ij',1,-6)
False
>>> s.endswith('ij',1,-5)
True