zoukankan      html  css  js  c++  java
  • 成员资格

     1 #为了检查一个值是否在序列中,Python为我们提供了in运算符。in运算符和前面讨论过的运算符有些不同。in运算符用于检测某个条件是否为真,检测结果为真返回True,结果为假返回False。这种运算符称作布尔运算符,返回的真值叫做“布尔值”。例:
     2 >>> greeting='hello,world'
     3 >>> 'w' in greeting
     4 True
     5 >>> 'a' in greeting
     6 False
     7 >>> users=['xiaomeng','xiaozhi','xiaoxiao']
     8 >>> 'xiaomeng' in users
     9 True
    10 >>> 'xiaohuai' in users
    11 False
    12 >>> numbers=[1,2,3,4,5]
    13 >>> 1 in numbers
    14 True
    15 >>> 6 in numbers
    16 False
    17 >>> eng='**Study python is so happy!**'
    18 >>> '**' in eng
    19 True
    20 >>> '$' in eng
    21 False
    22 >>> 'a' in numbers
    23 False
    24 >>> 3 in greeting
    25 Traceback (most recent call last):
    26   File "<pyshell#50>", line 1, in <module>
    27     3 in greeting
    28 TypeError: 'in <string>' requires string as left operand, not int
    29 #由上面的输出结果可以看到,使用in可以很好的检测字符或数字是否在对应的列表中。并且可以看出,数字类型不能再字符串类型中通过in进行成员资格检测,而字符串类型可以在数字列表中通过in进行成员资格检测。
  • 相关阅读:
    JDK+Jmeter 环境搭建
    APP自动化中三大定位工具
    APP自动化环境配置
    pytest生成allure报告
    pytest怎么标记用例?
    pytest中怎么实现参数化?
    pytest中怎么引用前置中的变量
    pytest_前置后置
    toast文本提示信息元素获取
    js处理日历
  • 原文地址:https://www.cnblogs.com/DLHe/p/7674454.html
Copyright © 2011-2022 走看看