思路:
# 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
本文介绍了一种检查连续三个单词是否全部由字母组成的Python函数,并演示了如何使用str.isalpha()等方法进行字符验证。
865

被折叠的 条评论
为什么被折叠?



