python string position code example
Example 1: python string indexing
str = 'codegrepper'
print(str[:])
print(str[::])
print(str[5:])
print(str[:8])
print(str[::2])
print(str[2:8])
print(str[2:8:2])
print(str[::-1])
print(str[::-3])
print(str[8:3:-1])
Example 2: 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
Example 3: python string indexof
s = "mouse"
animal_letter = s.find('s')
print animal_letter
Example 4: strings in python
myString = "Hello world"
print(myString)
myArr = []
myArr.append(myString)
H = myString[0]
lowercase = myString.lower()
myInt = int(myString)
Example 5: how to find position of a character in a string from right sidepython
>>> s = 'hello'
>>> s.rfind('l')
3
Example 6: python string index od
str.index(sub[, start[, end]] )