如何在python中检查双端队列的长度?
How to check a deque's length in python?
我没有看到他们在 Python 中提供 deque.length...
I don't see they provide deque.length in Python...
docs.python/tutorial/datastructures.html
from collections import deque queue = deque(["Eric", "John", "Michael"])如何查看这个双端队列的长度?
How to check the length of this deque?
我们可以像这样初始化
queue = deque([]) #is this length 0 deque? 推荐答案len(queue) 应该给你结果,在这种情况下是 3.
len(queue) should give you the result, 3 in this case.
具体来说,len(object) 函数会调用 object.__len__ 方法 [参考链接].而本例中的对象是deque,它实现了__len__方法(可以通过dir(deque)看到).
Specifically, len(object) function will call object.__len__ method [reference link]. And the object in this case is deque, which implements __len__ method (you can see it by dir(deque)).
queue= deque([]) #is this length 0 queue?是的,对于空的 deque,它将是 0.
Yes it will be 0 for empty deque.