最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在 Python 中检查双端队列长度

SEO心得admin54浏览0评论
本文介绍了如何在 Python 中检查双端队列长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在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.

发布评论

评论列表(0)

  1. 暂无评论