如何在Python中检查队列长度 [英] How to check queue length in Python
本文介绍了如何在Python中检查队列长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在python中检查队列的长度?
How to check Queue's length in python?
我没有看到它们在python中提供Queue.lenght...。
I dont see they provide Queue.lenght in python....
http://docs.python.org/tutorial/datastructures.html
from collections import deque
queue = deque(["Eric", "John", "Michael"])
如何检查此队列的长度?
how to check the length of this queue?
我们可以像
queue= deque([]) #is this length 0 queue?
推荐答案
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
这篇关于如何在Python中检查队列长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文