赞
踩
@R星校长
2
关:逻辑运算符Python 中的逻辑运算符包括如下三种:
and
:逻辑与;or
:逻辑或;not
:逻辑非。and逻辑与
逻辑表达式为x and y
。当 x
为 False
时,x and y
返回False
,否则它返回y
的计算值。
or逻辑或
逻辑表达式为x or y
。当x
为true
、y
为false
时,得到的结果为true
。只有当x
与y
都为false
时,得到的结果才为false
。如果 x
是非0
,它返回x
的值,否则它返回y
的计算值。
not逻辑非
逻辑表达式为not x
。当x
为true
时,得到的结果为false
,当x
为false
时,得到的结果为true
。
如果您想了解更多运算符的相关知识,请参考:[美] Katie Cunningham 著《 Python 入门经典》
第二章
# 定义逻辑运算处理函数theLogic,其中tom与Jerry分别代表两个输入参数 def theLogic(tom,jerry): # 请在此处填入jerry的布尔“非”代码,并将结果存入到not_result这个变量 ########## Begin ########## not_result = not jerry ########## End ########## print(not_result) # 请在此处填入tom,jerry的逻辑与代码,并将结果存入到and_result这个变量 ########## Begin ########## and_result = tom and jerry ########## End ########## print(and_result)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。