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程序设计有所帮助。

相关文章

妙用itchat! python实现久坐提醒功能

本文实例为大家分享了python久坐提醒的具体实现代码,供大家参考,具体内容如下 #!/usr/bin/envy python3 #-*- coding:utf-8 -*- impo...

通过Python编写一个简单登录功能过程解析

需求: 写一个登录的程序, 1、最多登陆失败3次 2、登录成功,提示欢迎xx登录,今天的日期是xxx,程序结束 3、要检验输入是否为空,账号和密码不能为空 4、账号不区分大小写...

python numpy 按行归一化的实例

如下所示: import numpy as np Z=np.random.random((5,5)) Zmax,Zmin=Z.max(axis=0),Z.min(axis=0) Z...

django drf框架自带的路由及最简化的视图

django-drf框架自带的路由以及最简化的视图,具体内容如下所示: 路由 一.导入模块 from rest_framework.routers import SimpleRout...

python sort、sorted高级排序技巧

Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列。 1)排序基础 简单的升序排序是非常容易的。只需要...