Home >>Python Built-in Functions >Python slice() Function
Python slice() function is used to return a slice object. The slice object is used to specify how to slice a sequence.
Syntax:slice(start, end, step)
Parameter | Description |
---|---|
start | This is an optional parameter. It defines an integer number specifying at which position to start the slicing. |
end | This parameter defines an integer number specifying at which position to end the slicing. |
step | This is an optional parameter. It defines an integer number specifying the step of the slicing. |
a = ("a", "b", "c", "d", "e", "f", "g", "h")
x = slice(5)
print(a[x])
a = ("a", "b", "c", "d", "e", "f", "g", "h")
x = slice(0, 8, 2)
print(a[x])