3
I’m studying about lines in Python and I’m using the object deque
module Collections.
So, in Python I can access the values of an array by simply writing:
array = [1, 2, 3]
arra[0] # 1
However, the object deque
also allows me to access the values of the queue through an index, with the same array notation.
Behold:
fila = deque()
fila.append(1)
fila.append(2)
fila.append(3)
fila[0] # 1
Only the array is of the class list
and the fila
is of class deque
module collections
see below:
print(type(fila))
print(type(array))
Exit:
<class 'collections.deque'>
<class 'list'>
And this left me with the following doubt.
Doubt
- The guy
list
is what determines the variable as array? If so, how does an object of the type of another class (i.e.deque
) can have the same behavior as an array?
Define "same array behavior".
– Maniero
@Maniero the possibility of accessing the value directly through an index. Of course there must be other definitions, but do not know :)
– gato
cat notices that a
tuple
according to this definition (possibility to access through an Index) can also be an array, e.g.:(1,2,3)[0] == 1
– Miguel
@Miguel then tupla is an array too, this I didn’t even imagine xD
– gato