Sanket
0
Q:

find in python


def find_all_indexes(input_str, search_str):
    l1 = []
    length = len(input_str)
    index = 0
    while index < length:
        i = input_str.find(search_str, index)
        if i == -1:
            return l1
        l1.append(i)
        index = i + 1
    return l1


s = 'abaacdaa12aa2'
print(find_all_indexes(s, 'a'))
print(find_all_indexes(s, 'aa'))
5
>> Line = ('I love becon.')#First we set a string
>> Index = Line.find('o')#Then we find when is the first instance of a letter or value
>> Print(Index)#Then we print it

Output>> 3 #We get 'o' because it's is the 3-rd letter in the string.
0
word = 'geeks for geeks'
  
# returns first occurrence of Substring 
result = word.find('geeks') 
print ("Substring 'geeks' found at index:", result ) 
  
result = word.find('for') 
print ("Substring 'for ' found at index:", result ) 
  
# How to use find() 
if (word.find('pawan') != -1): 
    print ("Contains given substring ") 
else: 
    print ("Doesn't contains given substring") 
2

New to Communities?

Join the community