+ 1

How to print a range of list ?

x=[1,3,5,7,9,11,13,15,17,19] if I want to print the numbers from the forth to the seventh, how can I do? print(x[3]) can only print the forth number

1st Aug 2020, 12:59 PM
DavidYAi
1 Antwort
+ 7
What codemonkey mentioned is called a slice. It has 3 parameters: [a:b:c] index is zero based, so to get from the first element [0:.. is used a - start index - including this index number b - end index - NOT including this index number c- step - defines if all, or only each 2nd, 3rd,... element will be taken To get more info about slices please go to the Learn section, and use search bar.
1st Aug 2020, 1:38 PM
Lothar
Lothar - avatar