Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = "Hello Python!"
- print(s.find('H'))
- # output: 0
- # if more than one occurance, return the first index
- print(s.find('o'))
- # output : 4
- # we can search from the end instead of the beginning
- print(s.rfind('o'))
- # output : 10
- # or we can start searching from a particular location
- print(s.find('o', 5)) # start searching from index 5, i.e. the whitespace
- # output : 10
- # search substring
- print(s.find('Pyt'))
- # output : 6
- # if not found
- print(s.find('x'))
- # output : -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement