【python小练习集】

1、字符串转换 TEST to test:将字符串涉及‘T’,‘E’,‘S’,‘T’的字符全部转换为小写

    msg = '''
    Hello It's A TEST Program
    I love Testing
    Hhh, this is a Test
    '''
    msg = msg.strip('\n')
    result = []
    for word in msg:
        deststr = re.findall('[TEST]', word)
        if len(deststr) > 0:
            result.append(word.lower())
        else:
            result.append(word)
    resultmsg = ''.join(result)
    print(resultmsg)

输出:
    Hello It's A test Program
    I love testing
    Hhh, this is a test
    

  

posted @ 2021-10-29 10:03  七彩蜗牛  阅读(23)  评论(0编辑  收藏  举报