+ 2

Finding index of substring

How can I find the index of a substring(for both single and multiple occurence) in python without using any in-built function?

27th May 2020, 2:29 PM
BADAL BAHINIPATI
BADAL BAHINIPATI - avatar
6 Antworten
+ 2
Incase you want a string x = "hello world hello I am namit jain hello everyone" y = "hello" for i in range(len(x) - len(y)): if x[i] == y[0] and x[i + 1] == y[1] and x[i + 2] == y[2] and x[i + 3] == y[3] and x[i + 4] == y[4]: print(x.index(x[i]) But you can simply use the re module
27th May 2020, 2:37 PM
Namit Jain
Namit Jain - avatar
+ 3
BADAL BAHINIPATI No problem bhaiya👍👍👍
27th May 2020, 2:40 PM
Namit Jain
Namit Jain - avatar
+ 2
x = input() y = input("Enter the desired character") for i in x: if i == y: print(x.index(i))
27th May 2020, 2:31 PM
Namit Jain
Namit Jain - avatar
+ 1
Can suggest from where can I learn thoroughly about working with strings in python?
27th May 2020, 2:36 PM
BADAL BAHINIPATI
BADAL BAHINIPATI - avatar
+ 1
Ok bro thank you
27th May 2020, 2:38 PM
BADAL BAHINIPATI
BADAL BAHINIPATI - avatar
+ 1
SoloLearn will provide all the syntax to work with strings... Now according to me you can solve the code coach problems and if you want more then buy the pro, in order to get some practice and learn their application
27th May 2020, 2:38 PM
Namit Jain
Namit Jain - avatar