Slice a string : slice « String « Python Tutorial






pystr = 'Python'
iscool = 'is cool!'
print pystr[0]
print pystr[2:5]
print iscool[:2]
print iscool[3:]
print iscool[-1]








5.29.slice
5.29.1.Slice a string
5.29.2.How to Access Values (Characters and Substrings) in Strings
5.29.3.for any ranges [start:end], we get all characters starting at offset start up to, but not including, the character at end.
5.29.4.When either a starting or an ending index is missing, they default to the beginning or end of the string, respectively.