是否有不同的方法来检查python中的deque空(is there a different ways to check deque empty in python)

编程入门 行业动态 更新时间:2024-10-10 10:26:24
是否有不同的方法来检查python中的deque空(is there a different ways to check deque empty in python)

它们是一样的吗????

while len(deque)>0: deque.popleft() while deque: deque.popleft()

所以基本上这两个条件循环可以避免从空队列中弹出?

Are they the same thing????

while len(deque)>0: deque.popleft() while deque: deque.popleft()

so basically these two condition loops can avoid poping from empty queue?

最满意答案

它们是相同的,但PEP 8更喜欢第二个版本。 我不相信它总是更容易阅读,所以要用自己的判断。

http://www.python.org/dev/peps/pep-0008/#programming-recommendations

对于序列,(字符串,列表,元组),请使用空序列为假的事实。

Yes: if not seq: if seq: No: if len(seq) if not len(seq)

They're the same, but PEP 8 prefers the second version. I'm not convinced that it's always easier to read though, so use your own judgement.

http://www.python.org/dev/peps/pep-0008/#programming-recommendations

For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

Yes: if not seq: if seq: No: if len(seq) if not len(seq)

更多推荐

本文发布于:2023-08-07 07:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法来   python   deque   empty   check

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!