내가 한 노력들

2020-10-30 python string 변수안에 특정 문자열 찾기 본문

IT 공부/python

2020-10-30 python string 변수안에 특정 문자열 찾기

JONGI-N CHOI 2020. 10. 30. 22:14

1. 특정 문자열이 포함되어 있는지 확인할때

string = 'test test test'

if 'test in string:

print string

 

 

2. 특정 문자열이 포함된 위치를 확인할 때

string = "this is test string"

print string.find("test")

 

3. 특정 문자열이 여러번 포함된 경우

import re

st = [m.start() for m in re.finditer('test', 'test test test test')]

print st



출처: https://metagenomics.tistory.com/entry/여러번-찾기 [메타지노믹스]