str1 = "If you're reading this half sentence you are amazing because it's half."
나는 전체 string.I의 길이를하지 않으려는 길이를 필요 -문장에 특정 단어까지 길이를 계산하는 방법
은사용
str.find
는
str1 = "If you're reading this half sentence you are amazing because it's half."
나는 전체 string.I의 길이를하지 않으려는 길이를 필요 -문장에 특정 단어까지 길이를 계산하는 방법
은사용
str.find
는
"이 반 문장을 읽고있는 경우에 당신은 놀라운".
예 :
>>> str1 = "If you reading this half sentence you are amazing because it's half."
>>> print(str1.find('because'))
50
당신은 다른 기능 str.index을 (사용할 수 있습니다),이 같은 일을한다. find()와 index() 사이의 유일한 차이점은 find() 메서드는 하위 문자열을 찾지 못하면 -1을 반환하지만 index() 메서드는 예외를 발생시킵니다. 사용법 : len = str1.index ('because')
공백을 포함해야하나요?
def find_till_word(sentence, word):
count = 0
for char in sentence[:sentence.index(word)]:
count += 1
return count
출력 :
>>> str1 = "If you reading this half sentence you are amazing because it's half."
>>> print(find_till_word(str1, "because"))
50