You can use slicing to extract a portion of a string, tuple, or list in Python. Slicing allows you to select a contiguous section of the sequence by specifying a start and stop index along with an optional step value.
Here is the syntax for slicing:
main.py26 chars2 lines
start
: Optional. Starting index of the slice. Defaults to 0 if not provided.stop
: Ending index (exclusive) of the slice. Defaults to the length of the sequence if not provided.step
: Optional. Step size of the slice. Defaults to 1 if not provided.Here are some examples of slicing in Python:
main.py587 chars27 lines
gistlibby LogSnag