版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/welcom_/article/details/83722049
思路:
# 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