1. 程式人生 > >Three Words [isalpha() 字母]

Three Words [isalpha() 字母]

思路:

# Three Words
# 
def checkio(words: str) -> bool:
    words=(words.split())
    count_1=0
    for x in words:
        if x.isalpha():
            count_1+=1
        else:
            count_1=0
        if count_1==3:
            return True
    return False


#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
    assert checkio("Hello World hello") == True, "Hello"
    assert checkio("He is 123 man") == False, "123 man"
    assert checkio("1 2 3 4") == False, "Digits"
    assert checkio("bla bla bla bla") == True, "Bla Bla"
    assert checkio("Hi") == False, "Hi"
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

擴充套件:

str.isalnum()# 所有字元都是數字或者字母 
str.isalpha()# 所有字元都是字母 
str.isdigit()# 所有字元都是數字 
str.islower()# 所有字元都是小寫 
str.isupper() #所有字元都是大寫 
str.istitle() #所有單詞都是首字母大寫,像標題 
str.isspace()# 所有字元都是空白字元、\t、\n、\r