【发布时间】:2015-06-09 21:02:30
【问题描述】:
我无法弄清楚上述问题并且有一种感觉,我应该用“for character in string”测试每个字符,但是我真的不知道它是如何工作的
这是我现在拥有的,但我知道它不能按预期工作,因为它只允许我测试字母但我还需要知道空格,例如“MY Dear aunt sally”应该说是只包含字母和空格
#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吗?
标签: python string python-3.x for-loop