python queue的用法

import queue

#先进先出
q=queue.Queue(2)
q.put(123)
q.put(456)
print(q.get())
print(q.qsize())

# 后进先出队列
q = queue.LifoQueue()
q.put(123)
q.put(456)
print(q.get())

# 优先级队列
# 当优先级相同时,按放数据顺序取数据
q1 = queue.PriorityQueue()
q.put((1, "alex1"))
q.put((2, "alex2"))
print(q1)

# 双向队列
q2 = queue.deque()
q2.append(123)
q2.append(456)
q2.appendleft(333)
print(q2)

输出结果为:
123
1
456

deque([333, 123, 456])

Process finished with exit code 0

转自:https://www.cnblogs.com/Z-style/p/5690146.html

你可能感兴趣的:(python)