Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python queue get size, use qsize() or len()?

Tags:

python

queue

size

I've seen instances where qsize() and len() has been used to compute the size of the queue. What is the distinction between the two?

like image 448
mingxiao Avatar asked Dec 18 '13 00:12

mingxiao


People also ask

How do I find the size of a Python queue?

To get the length of a queue in Python:Use the len() function to get the length of a deque object. Use the qsize() method to get the length of a queue object.

How do I find the size of a queue?

The queue. size() function in C++ returns the number of elements in the queue. In short, this function is used to get the current size of the queue.

What does the value returned by the Qsize () function of a queue represent?

The method qsize() returns the number of elements present in a queue.

Which data type is best for queue in Python?

List is a Python's built-in data structure that can be used as a queue.


1 Answers

For most containers, you'll want len, but Queue.Queue doesn't actually support len. This may be because it's old or because getting the length of a queue in a multithreaded environment isn't particularly useful. In any case, if you want the (approximate) size of a Queue, you want qsize.

like image 200
user2357112 supports Monica Avatar answered Sep 20 '22 17:09

user2357112 supports Monica