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

相关文章

python 实现tar文件压缩解压的实例详解

python 实现tar文件压缩解压的实例详解 压缩文件: import tarfile import os def tar(fname): t = tarfile.op...

Python根据已知邻接矩阵绘制无向图操作示例

Python根据已知邻接矩阵绘制无向图操作示例

本文实例讲述了Python根据已知邻接矩阵绘制无向图操作。分享给大家供大家参考,具体如下: 有六个点:[0,1,2,3,4,5,6],六个点之间的邻接矩阵如表格所示,根据邻接矩阵绘制出相...

解决新版Pycharm中Matplotlib图像不在弹出独立的显示窗口问题

解决新版Pycharm中Matplotlib图像不在弹出独立的显示窗口问题

官方说明链接: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000736584-SciView-...

Python实现修改IE注册表功能示例

Python实现修改IE注册表功能示例

本文实例讲述了Python实现修改IE注册表功能。分享给大家供大家参考,具体如下: 一、代码 # -*- coding:utf-8 -*- #! python3 import dat...

PyCharm中代码字体大小调整方法

PyCharm中代码字体大小调整方法

Python的火也引发了Python编辑器的火,那么作为Python编辑器的PyCharm对于代码字体大小该怎么调整呢,小编此次就带给大家调整方法 首先在桌面找到PyCharm软件打开,...