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数据结构与算法(几种排序)小结

Python数据结构与算法(几种排序)小结

Python数据结构与算法(几种排序) 数据结构与算法(Python) 冒泡排序 冒泡排序(英语:Bubble Sort)是一种简单的排序算法。它重复地遍历要排序的数列,一次比较两个...

获取django框架orm query执行的sql语句实现方法分析

获取django框架orm query执行的sql语句实现方法分析

本文实例讲述了获取django框架orm query执行的sql语句实现方法。分享给大家供大家参考,具体如下: 利用Django orM 可以很方便的写出很多查询,但有时候,我们需要检查...

Python 内置函数complex详解

英文文档: class complex([real[, imag]]) Return a complex number with the value real + imag*1j or...

PyQt5图形界面播放音乐的实例

安装Pygame pip install pygame import time import pygame pygame.init() print("播放音乐1") track =...

Python中使用pprint函数进行格式化输出的教程

pprint – 美观打印 作用:美观打印数据结构 pprint 包含一个“美观打印机”,用于生成数据结构的一个美观视图。格式化工具会生成数据结构的一些表示,不仅可以由解释器正确地解析,...