• python中if条件分支


    1、条件成立执行

    >>> a = 50
    >>> if a > 10:
        print("xxx")
    
        
    xxx
    >>> if a < 10:
        print("yyy")
    
        
    >>> if a == 50:
        print("zzz")
    
        
    zzz
    score = int(input("score="))
    if 100 >= score >= 90:
        print("AAA")
    if 90 > score >= 80:
        print("BBB")
    if 80 > score >= 60:
        print("CCC")
    if 60 > score >= 0:
        print("DDD")
    if score > 100 or score <= 0:
        print("error! range: 0-100")
    score = int(input("score="))
    if 100 >= score >=90:
        print("AAA")
    else:
        if 90 > score >= 80:
           print("BBB")
        else:
            if 80 > score >= 60:
               print("CCC")
            else:
                if 60 > score >= 0:
                   print("DDD")
                else:
                    print("error! range:0-100")
    score = int(input("score:"))
    if 100 >= score >= 90:
        print("AAA")
    elif 90 > score >= 80:
        print("BBB")
    elif 80 > score >= 60:
        print("CCC")
    elif 60 > score >= 0:
        print("DDD")
    else:
        print("error! range: 0-100")
    >>> test1 = ["aaa","bbb","ccc","ddd"]
    >>> for i in test1:
        if i == "aaa":
            print(i.upper())
        else:
            print(i.title())
    
            
    AAA
    Bbb
    Ccc
    Ddd
    >>> for i in test1:
        if i == "bbb":
            print(i.upper())
        else:
            print("_".join(i))
    
            
    a_a_a
    BBB
    c_c_c
    d_d_d
    >>> test1 = ["aaa","bbb","ccc","ddd"]
    >>> for i in test1:
        if i == "ccc":
            print(i.upper())
        else:
            print(i.replace("a","xxx"))
    
            
    xxxxxxxxx
    bbb
    CCC
    ddd
    >>> for i in test1:
        if i == "aaa" or i == "bbb":
            print("+".join(i))
        else:
            print(i.title())
    
            
    a+a+a
    b+b+b
    Ccc
    Ddd
  • 相关阅读:
    microsoft visual studio 不能逐句执行?
    【转】字符编码笔记:ASCII,Unicode和UTF-8
    【PNG格式中文详解】
    PHP 下载网络图片
    Install MongoDB on Windows (Windows下安装MongoDB)
    S2SH商用后台权限系统第二讲
    S2SH商用后台权限系统第一讲
    linux 常用命令
    简单的angular表单验证指令
    angular随笔
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14193067.html
Copyright © 2020-2023  润新知