What is slicing in python?

Slicing is a feature in python that enables us to get a subset of a sequence like string or list. Slicing is making things smaller by cutting out a piece.
We can slice sequence in two ways:-
- By using slice() function.
syntax:-
slice(start, stop, step)
e.g.,
a=('1', '2', '3', '4', '5', '6', '7', '8', '9', '0') b=slice(0, 4, 1) print(a[b])

- By using slicing method.
synatx:-
sequence_name[start: stop:end]
e.g.,
s="PYTHONPOINT" print(s[0:6:1])

This is about slicing in python.
Subscribe
Login
Please login to comment
0 Discussion