python code to remove character after last match character code example
Example 1: python remove last character from string
str = "string"
str = str[:-1]
Example 2: python remove last part of string
foo = foo[:-3]
Example 3: python extract substring
string = "freeCodeCamp"
print(string[0:len(string)-1])
print(string[0:5])
print(string[2:6])
print(string[-1])
print(string[-5:])
print(string[1:-4])
print(string[-5:-2])
print(string[::2])
Example 4: python remove last 4 characters from string
foo = foo[:-n]