+ 1

Slice in python

I don't know what is slice

21st Jul 2024, 8:06 AM
Vinitha
Vinitha - avatar
2 odpowiedzi
+ 4
In python, Slice is a way to extract a subset of elements from a list, tuple or string. It can take 3 arguments:- my_list[start_value: stop_value: step_value] Here, start_value defines the index of first element to include(default is 0) stop_value defines the index of last element to include(default is end of the list) step_value is the increament between elements(default is 1). Example:- my_list = [2,4,6,8,10] print(my_list[1:4:1]) #Output:- [4,6,8] You can use the same with tuple and string. Use the python course to understand it perfectly couse name Introduction to python, module name working with lists, lesson name Slicing.
21st Jul 2024, 8:17 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 2
Tq
21st Jul 2024, 8:21 AM
Vinitha
Vinitha - avatar