python队列的使用方法
2019-04-17 16:44
267 查看
队列——先进先出原则
创建队列:collections.deque()
队列中添加元素:collections.deque()
获取队列中的元素:同列表类似
-
import collections
-
n=3 #设定创建队列的大小
-
buffer=collections.deque(maxlen=n) #创建队列
-
for i in range(n): #队列中添加元素
-
buffer.append(i)
-
buffer.append(4)
-
for i in range(n): #获取队列中的元素
-
print(buffer[i])
相关文章推荐
- Python使用list的append和pop方法创建堆栈和队列实例代码
- Python队列的定义与使用方法示例
- Python __getattr__与__setattr__使用方法
- Python httplib,smtplib使用方法
- 【python cookbook】简化字符串的translate 方法的使用
- python下使用qrcode方法
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- python 基本类型 使用方法
- 【python】【scrapy】使用方法概要(二)
- Python httplib,smtplib使用方法
- uCOS II 消息队列的使用方法
- stl中优先队列的使用方法
- java中队列的使用方法
- Python 中的strip lstrip rstrip使用方法 .
- python simplejson模块的使用方法
- C++ Queues(队列)成员函数及其使用方法
- Python中使用中文的方法
- Python __getattr__与__setattr__使用方法
- 内核的 工作队列 使用方法,struct work_struct
- Python __getattr__与__setattr__使用方法