• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现队列的方法

Python实现队列的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python实现队列,python 队列,python redis 队列,python 的队列管理,python 消息队列等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python实现队列的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/env python 
queue = [] 
def enQ(): 
  queue.append(raw_input('Enter new string: ').strip())
#调用list的列表的pop()函数.pop(0)为列表的第一个元素 
def deQ(): 
  if len(queue) == 0: 
    print 'Cannot pop from an empty queue!' 
  else: 
    print 'Removed [', queue.pop(0) ,']' 
def viewQ(): 
  print queue 
CMDs = {'e': enQ, 'd': deQ, 'v': viewQ} 
def showmenu(): 
  pr = """ 
  (E)nqueue 
  (D)equeue 
  (V)iew 
  (Q)uit 
    Enter choice: """ 
  while True: 
    while True: 
      try: 
        choice = raw_input(pr).strip()[0].lower() 
      except (EOFError, KeyboardInterrupt, IndexError):
        choice = 'q' 
      print '\nYou picked: [%s]' % choice 
      if choice not in 'devq': 
        print 'Invalid option, try again' 
      else: 
        break 
    if choice == 'q': 
      break 
    CMDs[choice]() 
if __name__ == '__main__': 
  showmenu()
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python算法应用实战之队列详解
  • Python的消息队列包SnakeMQ使用初探
  • Python实现队列的方法
  • Python实现队列的方法
  • Python实现的数据结构与算法之队列详解
  • python基于mysql实现的简单队列以及跨进程锁实例详解
  • python基于mysql实现的简单队列以及跨进程锁实例详解

相关文章

  • python比较2个xml内容的方法
  • python处理大数字的方法
  • Python使用迭代器打印螺旋矩阵的思路及代码示例
  • Python使用Srapy框架爬虫模拟登陆并抓取知乎内容
  • Python实现统计文本文件字数的方法
  • Python Web框架Flask中使用七牛云存储实例
  • python实现问号表达式(?)的方法
  • python计算一个序列的平均值的方法
  • python实现类的静态变量用法实例
  • Python isinstance判断对象类型

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python文件操作之目录遍历实例分析
    • python使用内存zipfile对象在内存中打包文件示例
    • Python文件去除注释的方法
    • 编写简单的Python程序来判断文本的语种
    • python处理cookie详解
    • python基础教程之lambda表达式使用方法
    • python 图片验证码代码分享
    • 详解Python中的文件操作
    • 浅谈Python2.6和Python3.0中八进制数字表示的区别
    • tensorflow实现在函数中用tf.Print输出中间值

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有