• 技术文章 >后端开发 >Python教程

    python中的elif是什么意思

    尚2019-07-06 11:47:52原创42838

    elif是else if的简写。else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if、for、while语句内部的。else子句可以增加一种选择;而elif子句则是需要检查更多条件时会被使用,与if和else一同使用。

    实例:

    people = 30
    cars = 40
    buses = 15
      
      
    if cars > people: 
      print( "We should take the cars.")
    elif cars < people: 
      print ("We should not take the cars.")
    else: 
      print ("We can't dicide.")
      
      
    if buses > cars: 
      print ("That's too many buses.")
    elif buses < cars: 
      print ("Maybe we could take the buses.")
    else: 
      print ("We still can't decide.")
      
      
    if people > buses: 
      print ("Alright, let's just take the buses.")
    else: 
      print ("Fine, let's stay home then.")

    运行结果:

    1.jpg

    更多Python相关技术文章,请访问Python教程栏目进行学习!

    以上就是python中的elif是什么意思的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:python怎么查看变量类型 下一篇:python中什么是类
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• python变量名是什么• python怎么把两个列表合并• python双等号是什么意思• python爬虫通俗点讲是什么
    1/1

    PHP中文网