Answers for "python string find"

4

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'))
Posted by: Guest on February-16-2020
0

python string find

The find() method returns the index of first occurrence of the substring
(if found). If not found, it returns -1.
message = 'Python is a fun programming language'

# check the index of 'fun'
print(message.find('fun'))

# Output: 12
Posted by: Guest on September-13-2021
-1

find on string in python

string.find(value, start, end)
Posted by: Guest on April-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language