分岐構造のPythonの研究ノート、三項演算子、論理演算子

分岐構造

  • 単一の分岐

    # if一般用于判断/选择的场景
    # 90以上优秀
    score = 95
    if score > 90:
        print('优秀')# 双分支
  • デュアル支店

    # if...else
    # 90以上优秀,90一下良好
     score = 95
     if score > 90:
         print('优秀')
     else:
         print('良好')
  • 多分岐

    # if...elif...elif...else
    # if...if...if...if
    # 90以上优秀,90-70良好,70以下不及格
    score = 95
    if score > 90:
        print('优秀')
    elif score > 70:
        print('良好')
    else:
        print('及格')
        score = 95
    
    if score > 90:
        print('优秀')
    if score > 70 and score < 90: # 同时满足
        print('良好')
    if score < 60:
        print('及格')

おすすめ

転載: www.cnblogs.com/XuChengNotes/p/11235718.html