+ 1

How does this works?

A tuple into a list the print the index https://code.sololearn.com/c5r35LxEa8pP/?ref=app

8th Dec 2022, 5:46 PM
Bezu Tadesse
Bezu Tadesse - avatar
6 Answers
+ 1
k[4:2] is empty because the start number is bigger than the stop number. but it works if you add -1 as third number which is step . Default is 1 if you don't mention any. So as a default it moves from 4 forward so it prints empty list
9th Dec 2022, 12:24 PM
Kishore Kumar
+ 6
k[1:3] returns[ 2,3 ] And k[4:2]) returns empty So [2, 3] only...
8th Dec 2022, 5:56 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 5
k[4, 2] start index is 4 and end index is 2 so already 4 exceeds 2. So no starts slice See list[ start, end, step_count ] : list slicing starts at start index, until end index by taking step_count for next index.
8th Dec 2022, 6:20 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
8th Dec 2022, 6:13 PM
Oma Falk
Oma Falk - avatar
+ 1
Why k[4:2] returns empty?
8th Dec 2022, 6:14 PM
Bezu Tadesse
Bezu Tadesse - avatar
+ 1
Thanks Jayakrishna that's the best answer!
8th Dec 2022, 6:32 PM
Bezu Tadesse
Bezu Tadesse - avatar