Skip to content

Slices and walking a list

Read · 1 of 4

Slices

nums[1:3] is the part from position 1 up to (not including) 3. nums[:2] is the first two, nums[2:] everything from position 2.

nums[::-1] is the whole list backwards. Loop with positions using for i in range(len(nums)):.