python成员运算符包括_Python 使用成员运算符案例
什么是操作符?
簡單的回答可以使用表達式4 + 5等于9,在這里4和5被稱為操作數,+被稱為操符。 Python語言支持操作者有以下幾種類型。
算術運算符
比較(即關系)運算符
賦值運算符
邏輯運算符
位運算符
會員操作符
標識操作符
下面簡單介紹一下,Python的成員運算符,下表列出了所有Python語言支持的成員運算符。操作符描述示例
in計算結果為true,如果它在指定找到變量的順序,否則false。x在y中,在這里產生一個1,如果x是序列y的成員。
not in計算結果為true,如果它不找到在指定的變量順序,否則為false。x不在y中,這里產生結果不為1,如果x不是序列y的成員。
Python編程語言提供會員運算符,代碼實現如下:#!/usr/bin/python
a = 10
b = 20
list = [1, 2, 3, 4, 5 ];
if ( a in list ):
print "Line 1 - a is available in the given list"
else:
print "Line 1 - a is not available in the given list"
if ( b not in list ):
print "Line 2 - b is not available in the given list"
else:
print "Line 2 - b is available in the given list"
a = 2
if ( a in list ):
print "Line 3 - a is available in the given list"
else:
print "Line 3 - a is not available in the given list"
執行結果如下:Line 1 - a is not available in the given list
Line 2 - b is not available in the given list
Line 3 - a is available in the given list
總結
以上是生活随笔為你收集整理的python成员运算符包括_Python 使用成员运算符案例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python文字游戏 生成数字菜单_py
- 下一篇: 如何把一个网页生成一个快捷方式在桌面?_