-
-
Save IndhumathyChelliah/e0987c9feca9579cd0987fe20724fafb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1="HelloWorld!" | |
#Returns lowest index | |
print (s1.find("o"))#Output:4 | |
print (s1.index("o"))#Output:4 | |
#Returns highest index | |
print (s1.rfind("o"))#Output:6 | |
print (s1.rindex("o"))#Output:6 | |
#When substring is not found | |
#Returns -1 | |
print (s1.find("z"))#Output:-1 | |
print (s1.rfind("z"))#Output:-1 | |
#Raises ValueError | |
#print (s1.index("z"))#Output:ValueError: substring not found | |
#print (s1.rindex("z"))#Output:ValueError: substring not found | |
#start and end index is mentioned | |
print (s1.find("o",3,5))#Output:4 | |
print (s1.rfind("o",3,5))#Output:4 | |
print (s1.index("o",3,5))#Output:4 | |
print (s1.rindex("o",3,5))#Output:4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment