+ 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?
6 odpowiedzi
+ 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
+ 3
BADAL BAHINIPATI No problem bhaiya👍👍👍
+ 2
x = input()
y = input("Enter the desired character")
for i in x:
if i == y:
print(x.index(i))
+ 1
Can suggest from where can I learn thoroughly about working with strings in python?
+ 1
Ok bro thank you
+ 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