N
N
NoALoser2020-06-16 13:09:13
Python
NoALoser, 2020-06-16 13:09:13

Python, what is the difference between indexing and slicing?

I want to update the list, but I don't understand what is the difference between indexing and slicing: why is 33 in the first version without square brackets, and in the second - with?

a = [1,2,3]
a[0:1] = [33]
a
Ответ: [33,2,3]

и 

a = [1,2,3]
a[0] = [33]
a
Ответ:  
a[0] returns this same element, that is, a[0]

D
Dr. Bacon, 2020-06-16
@bacon

index - one specific element
slice - a slice of elements in the specified range (may contain one element)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question