小编hel*_*ase的帖子

如何判断字符串是否只包含字母AND空格

我无法弄清楚上面的问题并且有一个感觉我应该用"为字符串中的字符"测试每个字符但是我无法弄清楚它是如何工作的

这就是我现在所拥有但我知道它不能按预期工作,因为它只允许我测试字母,但我也需要知道空格,例如"我亲爱的阿姨莎莉"应该说是只包含字母和空格

    #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")
Run Code Online (Sandbox Code Playgroud)

python string for-loop python-3.x

4
推荐指数
1
解决办法
2179
查看次数

标签 统计

for-loop ×1

python ×1

python-3.x ×1

string ×1