多个If和Elif的Python之间的区别 [英] Difference Between Multiple If's and Elif's Python

查看:349
本文介绍了多个If和Elif的Python之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,说:

In python, is there a difference between say:

if text == 'sometext':
    print(text)
if text == 'nottext':
    print("notanytext")

 if text == 'sometext':
        print(text)
 elif text == 'nottext':
        print("notanytext")

只是想知道是否有多个ifs可能导致任何不必要的问题,如果更好的做法是使用elifs

Just wondering if multiple ifs could cause any unwanted problems and if it was better practice to use elifs

推荐答案

多个if表示你的代码会去检查所有if条件,如果是elif,如果一个条件满足它就不会检查其他条件..

Multiple if's means your code would go and check all the if conditions, where as in case of elif, if one if condition satisfies it would not check other conditions..

这篇关于多个If和Elif的Python之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆