I'm studying about queues in Python and I'm using the object deque
of the module collections .
So, in Python I can access the values of an array by index simply by typing:
array = [1, 2, 3]
arra[0] # 1
However, the deque
object also allows me to access the values of the queue through an index, with the same array notation.
See:
fila = deque()
fila.append(1)
fila.append(2)
fila.append(3)
fila[0] # 1
Only the array is of class list
and fila
is of class deque
of module collections
see below:
print(type(fila))
print(type(array))
Output:
<class 'collections.deque'>
<class 'list'>
And this left me with the following doubt.
Doubt
- Type
list
is what determines the variable as array? If yes, how does an object of the type of another class (i.e.deque
) have the same behavior as an array?