how to find the location of a character in a string in python
>>> myString = 'Position of a character'
>>> myString.find('s')
2
>>> myString.find('x')
-1
how to find the location of a character in a string in python
>>> myString = 'Position of a character'
>>> myString.find('s')
2
>>> myString.find('x')
-1
python string indexing
str = 'codegrepper'
# str[start:end:step]
#by default: start = 0, end = len(str), step = 1
print(str[:]) #codegrepper
print(str[::]) #codegrepper
print(str[5:]) #repper
print(str[:8]) #codegrep
print(str[::2]) #cdgepr
print(str[2:8]) #degrep
print(str[2:8:2]) #dge
#step < 0 : reverse
print(str[::-1]) #reppergedoc
print(str[::-3]) #rpgo
# str[start:end:-1] means start from the end, go backward and stop at start
print(str[8:3:-1]) #pperg
how to find position of a character in a string from right sidepython
>>> s = 'hello'
>>> s.rfind('l')
3
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us