>>> x = "Hello World!"
>>> x[2:]
'llo World!'
>>> x[:2]
'He'
>>> x[:-2]
'Hello Worl'
>>> x[-2:]
'd!'
>>> x[2:-2]
'llo Worl'
# string [start:end:step]
string = "freeCodeCamp"
print(string[0:len(string)-1]) # freeCodeCam
print(string[0:5]) # freeC
print(string[2:6]) # eeCo
print(string[-1]) # p
print(string[-5:]) # eCamp
print(string[1:-4]) # reeCode
print(string[-5:-2]) # eCa
print(string[::2]) # feCdCm
my_string = "I love python."
# prints "love"
print(my_string[2:6])
# prints "love python."
print(my_string[2:])
# prints "I love python"
print(my_string[:-1])
learn_coding = "You can learn to code for free! Yes, for free!"
substring = "paid"
print(learn_coding.index(substring))
# output
# Traceback (most recent call last):
# File "main.py", line 4, in <module>
# print(learn_coding.index(substring))
# ValueError: substring not found