To slice a string in Python, you can use square brackets []
with the start and end index separated by a colon :
. The end index is exclusive, meaning the character at that index will not be included in the slice. Here's an example:
main.py164 chars8 lines
You can also specify both the start and end index to slice a specific portion of the string:
main.py173 chars8 lines
Remember that indexing in Python starts from 0
, and negative indices can be used to slice from the end of the string.
gistlibby LogSnag