Óstáilte ar MSN

Master Python string slicing like a pro

Python string slicing is a concise way to extract parts of a string without loops, using start, end, and step values. You can also use negative indices to work from the end or reverse strings in one ...
GitHub

04_string_slicing.py

print(text_string[:10]) #If in the beginning there is blank then consider as Zero print(text_string[0:]) #If in the end there is blank then consider as len-1 ...
print(my_string[2:-2]) # Output: 'th', character at index -2 is NOT included print(my_string[-2]) # Output: 'thon', character at index -1 is included # : is used for slicing a sequence (like a list, ...