美文网首页
02-运算符

02-运算符

作者: zhangxuhui | 来源:发表于2017-12-08 15:10 被阅读0次
# -*- coding:utf-8 -*-
#逻辑运算符
#and or not
print(True and False)
print(True or False)
print(not False)
#如果两个都为真 返回最后一个真值
print(10 and 20)
#若有假值 返回第一个假
print(10 and 0)
print(0 and 20)

#成员运算符 in not in
list1 = ['a','b','c']
print('a' in list1)
print('a' not in list1)

#身份运算符is is not 类似于 id(a) == id(b)
#id函数获取当前对象在内存中的地址
a = 1
b = 1
c = 2
print(id(a))
print(id(b))
print(id(c))
#ab 同一个对象
print(a is b)
print(a is not b)
print(a is c)
print(a is not c)
位运算符
image.png image.png

相关文章

网友评论

      本文标题:02-运算符

      本文链接:https://www.haomeiwen.com/subject/ctveixtx.html