基本运算符
Posted martin-wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本运算符相关的知识,希望对你有一定的参考价值。
01 比较运算符
> >=
< <=
==
!=
print(10 != 11)
> >=
< <=
==
!=
print(10 != 11)
了解
x=None
print(x == None)
print(x is None)
x=None
print(x == None)
print(x is None)
l1=[‘abc‘,1,[‘a‘,‘b‘,‘c‘]]
l2=[‘abc‘,‘aa‘,]
print(l2 > l1)
l2=[‘abc‘,‘aa‘,]
print(l2 > l1)
02 逻辑运算符
and:连接左右两个条件,只有两个条件同时成立时and运算的结果为True
print(10 > 9 and 3 > 2 and ‘egon‘ == ‘egon‘ and True)
and:连接左右两个条件,只有两个条件同时成立时and运算的结果为True
print(10 > 9 and 3 > 2 and ‘egon‘ == ‘egon‘ and True)
or:连接左右两个条件,两个条件成立任意一个or运算的结果就为True
print(False or False or True or False or 3 > 10)
print(False or False or True or False or 3 > 10)
res=(True or (False and True)) or ((False or True) and False)
res=(True or False) or (True and False)
res=(True or False) or (True and False)
res=True or False
print(res)
print(res)
not
print(not 10 > 3)
print(not 10 > 3)
x=None
print(not x is None)
print(x is not None)
print(not x is None)
print(x is not None)
age1=18
age2=19
print(age2 is not age1)
print(age2 is not age1)
name_bk=‘egon‘
pwd_bak=‘123‘
name=input(‘please input your name: ‘)
pwd=input(‘please input your password: ‘)
if name == name_bk and pwd == pwd_bak:
print(‘login successfull‘)
print(‘login successfull‘)
print(‘login successfull‘)
print(‘login successfull‘)
print(‘login successfull‘)
else:
print(‘username or password error‘)
以上是关于基本运算符的主要内容,如果未能解决你的问题,请参考以下文章