2016-06-23 2 views

답변

2

"이 반 문장을 읽고있는 경우에 당신은 놀라운".

예 :

>>> str1 = "If you reading this half sentence you are amazing because it's half." 
>>> print(str1.find('because')) 
50 
0

당신은 다른 기능 str.index을 (사용할 수 있습니다),이 같은 일을한다. find()와 index() 사이의 유일한 차이점은 find() 메서드는 하위 문자열을 찾지 못하면 -1을 반환하지만 index() 메서드는 예외를 발생시킵니다. 사용법 : len = str1.index ('because')

0

공백을 포함해야하나요?

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 
관련 문제