Python 运算符练习 notand or

Python 运算符练习 notand or,第1张

概述# *** 作符练习,求打印的内容x=Truey=Falsez=Falseifnotxory:print(1)elifnotxornotyandz:print(2)elifnotxoryornotyandx:print(3)else:print(4)'''已知 *** 作符优先级顺序,not>and>oraandb若a为False返回a否
# *** 作符练习,求打印的内容x = Truey = Falsez = Falseif not x or y:    print(1)elif not x or not y and z:    print(2)elif not x or y or not y and x:    print(3)else:    print(4)'''已知 *** 作符优先级顺序,not > and > or a and  b  若a为False 返回a  否则返回b a or   b  若a为True 则返回a 否则返回b not a     若a为True 返回False 若a为False,则返回True我们看上面的表达式一个一个来解    if not x or y1:not优先级较高,先运算not x  因为x=True 所以 not x =False2.语句表达式解为: if False or y      y=False    3.语句表达式解为: if  False or False4.根据运算符规则, 该语句解为:False5.所以if not x or y  返回值为False 当前未命中,进入下一个if判断-----------------------------------  if not x  or  not y  and x1.not优先级较高, x = True  y = False    z = False2.语句表达式解为: if False or True and False3.语句中有or和and and优先级较高,先执行and运算4.语句表达式解为: if False or False6.语句表达式解为:if False所以该语句不会执行,进入下个语句判断------------------------------------------------    elif not x or y or not y and x:1.not优先级较高,先进行not运算  x = True  y = False    z = False2.语句表达式解为: elif False or False or True and True3.语句表达式有 or和and  根据优先级 and先预算4.语句表达式解为:elif False or False or True5.语句只有or 从左到右进行计算6.语句表达式解为:elif False  or True7.语句表达式解为:elif True8.语句表达式解为:elif True 9.语句为True 执行该段语句-------------------------------------------------------所以,最终函数打印的内容为:3'''

 

总结

以上是内存溢出为你收集整理的Python 运算符练习 not and or全部内容,希望文章能够帮你解决Python 运算符练习 not and or所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1185210.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存