网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Python逻辑操作中的三大应用方案

这篇文章给大家介绍Python逻辑操作中的三大应用方案,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

站在用户的角度思考问题,与客户深入沟通,找到雷山网站设计与雷山网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都做网站、网站制作、企业官网、英文网站、手机端网站、网站推广、主机域名虚拟主机、企业邮箱。业务覆盖雷山地区。

Python逻辑在运作中有不少的问题需要解决。在实际的使用中有三种:and、or、not。分别对应与、或、非。

举例:

#coding:utf-8  test1 = 12 test2 = 0 print (test1 > test2) and (test1 > 14) #result = False print (test1 < test2) or (test1 > -1) #result = True print (not test1) #result = False print (not test2) #result = True

严格的说,逻辑操作符的操作数应该为布尔表达式。但Python逻辑操作对此处理的比较灵活。即使操作数是数字,解释器也把他们当成“表达式”。非0的数字的布尔值为1,0的布尔值为0.

举例:

#coding:utf-8  test1 = 12 test2 = 0 print (test1 and test2) #result = 0 print (test1 or test2) #result = 12 print (not test1) #result = Flase print (not test2) #reslut = True

在Python逻辑操作中,空字符串为假,非空字符串为真。非零的数为真。

数字和字符串之间、字符串之间的逻辑操作规律是:

对于and操作符:只要左边的表达式为真,整个表达式返回的值是右边表达式的值,否则,返回左边表达式的值对于or操作符:只要两边的表达式为真,整个表达式的结果是左边表达式的值。

如果是一真一假,返回真值表达式的值,如果两个都是假,比如空值和0,返回的是右边的值。(空值或0)举例:

  1. #coding:utf-8   

  2. test1 = 12 

  3. test2 = 0   

  4. test3 = ''   

  5. test4 = "First"   

  6. print test1 and test3 #result = ''   

  7. print test3 and test1 #result = ''   

  8. print test1 and test4 #result = "First"   

  9. print test4 and test1 #result = 12 

  10. print test1 or test2 #result = 12 

  11. print test1 or test3 #result = 1212 print test3 or test4 
    #result = "First" 

  12. print test2 or test4 #result = "First" 

  13. print test1 or test4 #result = 12 

  14. print test4 or test1 #result = "First" 

  15. print test2 or test3 #result = '' 

  16. print test3 or test2 #result = 0 

关于Python逻辑操作中的三大应用方案就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


网站栏目:Python逻辑操作中的三大应用方案
网站路径:http://bjjierui.cn/article/gdjjgp.html

其他资讯