+ 1

Can someone help and explain better on slicing

I hardly get a lesson right while slicing

30th Jul 2025, 8:52 AM
peculiar benard
peculiar benard - avatar
3 Antworten
+ 2
peculiar benard Try using search bar before posting a question: https://www.sololearn.com/Discuss/3310243/?ref=app
30th Jul 2025, 9:09 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 1
Slices allow us to output arrays and perform various operations on them. For example: animals= ["cat", "dog", "bird", "bear", "fox"] favourite_animals = animals[2:] print(favourite_animals) Output: ["bird", "bear", "fox"] You can use slices starting from index 0. favourite_animals = animals[:2] print(favourite_animals) Output: ["cat, "dog"] And you can use the slices like this: favourite_animals = animals[1:4] print(favourite_animals) Output: ["dog", "bird", "bear"] So we understand that slices simplify our code.
30th Jul 2025, 9:15 AM
Mila
Mila - avatar
0
Slicing is like cutting a piece of cake 🍰 In python we use slicing for accessing the specific element Eg : We need 70,30 in the list only We access the elements with their index number start from 0 Basically 20 at -> 0 index list = [20,40,70,30,100] list = list[2:4] #they ignore 4th element,access only 2 and 3rd element as a slice 🍕 print(list)
30th Jul 2025, 9:08 AM
Amritpal Singh
Amritpal Singh - avatar