How to get the highest index of a substring inside a string with Python

2 Answers

0 votes
string = "php python java c python c++ python"
substring = "python"

idx = string.rindex('python')
print(idx)



'''
run:

29

'''

 



answered Dec 10, 2019 by avibootz
0 votes
string = "php python java c python c++ python"
substring = "python"
 
idx = string.rfind('python')
print(idx)
 
 
 
'''
run:
 
29
 
'''

 



answered Dec 11, 2019 by avibootz

Related questions

...