python实现判断数组是否包含指定元素的方法

yipeiwu_com6年前Python基础

本文实例讲述了python实现判断数组是否包含指定元素的方法。分享给大家供大家参考。具体如下:

python判断数组是否包含指定的元素的方法,直接使用in即可,python真是简单易懂

print 3 in [1, 2, 3] # membership (1 means true
inventory = ["sword", "armor", "shield", "healing potion"]
if "healing potion" in inventory:
  print "You will live to fight another day."

运行结果如下:

True
You will live to fight another day.

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

相关文章

VSCode中自动为Python文件添加头部注释

VSCode中自动为Python文件添加头部注释

在实际编写Python文件时,往往需要为文件添加相关说明,例如文件名称、文件作用、创建时间、作者信息、版本号等等。这些信息往往是固定模板的,因此希望有一种方式可以自动的为我们添加上这些信...

Django imgareaselect手动剪切头像实现方法

本文实例讲述了Django imgareaselect手动剪切头像的方法。分享给大家供大家参考。具体如下:  index.html: <!DOCTYPE html&g...

Django rest framework实现分页的示例

Django rest framework实现分页的示例

第一种分页PageNumberPagination 基本使用 (1)urls.py urlpatterns = [ re_path('(?P<version>...

Python中使用bidict模块双向字典结构的奇技淫巧

快速入门 模块提供三个类来处理一对一映射类型的一些操作 'bidict', 'inverted', 'namedbidict' >>> import bidict...

python持久性管理pickle模块详细介绍

持久性就是指保持对象,甚至在多次执行同一程序之间也保持对象。通过本文,您会对 Python对象的各种持久性机制(从关系数据库到 Python 的 pickle以及其它机制)有一个总体认识...