0

Whats wrong with the python

list = [1, 2, 3, 4] print(list[4])

25th Jan 2024, 11:35 AM
Python Vietnam
Python Vietnam - avatar
5 odpowiedzi
+ 5
Counting of index starts with 0 so at to acess 4 write it list[3]
25th Jan 2024, 2:16 PM
Nisha Choudhary
Nisha Choudhary - avatar
+ 14
Indexing starts with 0. There is no index 4 when the list has only 4 elements.
25th Jan 2024, 11:46 AM
Lisa
Lisa - avatar
+ 2
This list only have 0 to 3 index It means [1,2,3,4] 0,1,2,3
25th Jan 2024, 10:29 PM
Amirhassan gorji
Amirhassan gorji - avatar
+ 1
[1,2,3,4] 0 1 2 3 Working in slice to list[3:4] or list[:4], but not working with call to list[4] (list index out of range)
25th Jan 2024, 12:36 PM
Kunevich Evgeniyy Evgenievich
Kunevich Evgeniyy Evgenievich - avatar
+ 1
on all languages, no matter, C, Java, Python, anything starting from 0, not 1 like u got used to it. Read attentively lessons
26th Jan 2024, 5:55 PM
Igor Chaprov
Igor Chaprov - avatar