• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python if判断在哪写

python 搞java代码 3年前 (2022-05-21) 11次浏览 已收录 0个评论

if 结构允许程序做出选择,并根据不同的情况执行不同的操作

基本用法

比较运算符

根据 PEP 8 标准,比较运算符两侧应该各有一个空格,比如:5 == 3。 PEP8 标准 ==(相等):如果该运算符两侧的值完全相同则返

回 True !=(不等):与相等相反

推荐:Python教程

<a href="https://www.gaodaima.com/tag/print" title="查看更多关于print的文章" target="_blank">print</a>(5 == '5')
print(True == '1')
print(True == 1)
print('Eric'.lower() == 'eric'.lower())

www#gaodaima.com来源gaodai#ma#com搞@@代~&码网搞代码

>(大于):左侧大于右侧则输出 True                         

<(小于):与大于相反

>=(大于等于):左侧大于或者等于右侧则输出 True 

<=(小于等于):左侧小于或者等于右侧则输出 True

print(5 > 3)
print(2 > True)
print(True > False)

if的用法

 if 进行判断

desserts = ['ice cream', 'chocolate', 'apple crisp', 'cookies']
favorite_dessert = 'apple crisp'
hate_dessert = 'chocolate'

for dessert in desserts:
    if dessert == favorite_dessert:
        print("%s is my favorite dessert!" % dessert.title())

更多技术请关注云海天Python教程。

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python if判断在哪写

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址