多个if和elif之间的区别? [英] Difference between multiple if's and elif's?

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

问题描述

在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")

只想知道是否多个if会导致任何不必要的问题,以及使用elif s是否是更好的做法.

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

推荐答案

多个if表示您的代码将检查所有if条件,如elif的情况,如果if条件满足则将不检查其他条件.

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之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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