我无法弄清楚上述问题并有感染我应该用“字符串中的字符”测试每个字符,但是我无法真正弄清楚将工作我如何判断一个字符串是否只包含字母和空格
这是我现在的,但我知道它不工作,因为它只允许我测试字母,但我也需要知道空间,例如“我亲爱的阿姨莎莉”应该说是只包含字母和空格
#Find if string only contains letters and spaces
if string.isalpha():
print("Only alphabetic letters and spaces: yes")
else:
print("Only alphabetic letters and spaces: no")
您是否希望函数为'foo'返回true? – 2015-04-05 06:35:27