广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    如何在Python里使用if,else,elif

    来源:网络收集  点击:  时间:2024-05-16
    【导读】:
    在Python里使用if,else,elif工具/原料morePython方法/步骤1/6分步阅读

    打开python,这里以Jupyter notebook作为示范,新建一个文档。

    2/6

    单单只用if,如下:

    a = 5

    b = 9

    if a b:

    print (a is bigger than b)

    print(a is less than b)

    3/6

    IF和ELSE一起运用,看起来更容易理解:

    c = 6

    d = 8

    if c d:

    print(c is bigger than d)

    else:

    print(c is less than d)

    4/6

    IF、ELSE和ELIF三个一起使用,可以增加条件:

    e = 10

    f = 10

    if e f:

    print(e is bigger than f)

    elif e == f:

    print(e is equal to f)

    else:

    print(e is less than f)

    5/6

    e如果比f小:

    e = 10

    f = 13

    if e f:

    print(e is bigger than f)

    elif e == f:

    print(e is equal to f)

    else:

    print(e is less than f)

    6/6

    e如果比f大:

    e = 20

    f = 13

    if e f:

    print(e is bigger than f)

    elif e == f:

    print(e is equal to f)

    else:

    print(e is less than f)

    注意事项

    else后直接跟着冒号,不加其他

    PYTHONIFELSEELIF语句
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_776275.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号07-10 17:53:22  耗时:0.739