You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python treats string as a list of characters with index.
in the string “I love cheese”, the character “I” will have an index 0, followed by a space with an index 2, and so on.
myString = "I love cheese"
# To get the first letter/character
firstChar = myString[0]
# To get the last letter/character
lastChar = myString[-1]
# To get the last 4 letters/characters
last4Chars = myString[-4:0]
# To get the first 4 letters/characters
first4Chars = myString[0:4]
# To get the letters/characters between index 3 and 5
last4Chars = myString[3:6]
# To get the letters/characters starting from 3 but skipping one between until index 8
last4Chars = myString[3:8:2]