0

How can I get index (1) with values of 4 list [1, 2, 3, 1] on python

20th Dec 2019, 1:59 PM
dany setyawan
dany setyawan - avatar
5 Respostas
+ 4
You can give a start index, from where you want to look: thatlist.index(1, 1) The second argument is the position from where the method reads, so it doesn't get stuck at the first 1.
20th Dec 2019, 2:08 PM
HonFu
HonFu - avatar
+ 2
You will get index "1" in this way: mylist = [1, 2, 3, 1] print(mylist[1]) This will print: 2, because the '2' is on index 1 in this list. If you want to get the first element, you have to use Index '0'
20th Dec 2019, 2:16 PM
Coding Cat
Coding Cat - avatar
+ 2
HonFu , I hope so 😉 But now it's for me also not really clear
20th Dec 2019, 2:20 PM
Coding Cat
Coding Cat - avatar
+ 1
Ah, that's what was meant? I see...
20th Dec 2019, 2:17 PM
HonFu
HonFu - avatar
+ 1
Thanks for your answer all.
21st Dec 2019, 2:31 PM
dany setyawan
dany setyawan - avatar