0
How to select multiple elements from a list?
I think it is that code, but it's wrong. p = [1,2,3,4,5] print((p:3) returns[1,2,3])
5 ответов
+ 3
I suggest to progress with the python lessons on sololearn and you get there quickly.
Lists always begin with index 0.
To get the first 3 elements (that have index 0,1 and 2) you use:
p[:3]
Check the lesson for more examples
https://www.sololearn.com/learn/Python/2453/
+ 5
What you need to study for it: slice!
+ 2
You either need to use list slicing or to just index twice.
+ 1
what do you mean by select?
is that python?
do you want a sub-list containing certain elements from a list?
+ 1
Yes, Anton, I wanna sub-list with some elements (I've thought output is 1,2,3, but now I think it is 2,3,4 [because position 1 have variable 2]) . I read it on the site: https://www.listendata.com/2017/05/JUMP_LINK__&&__python__&&__JUMP_LINK-data-science.html?m=1#spyder_shortcut