当前位置:  首页>> 技术小册>> Python合辑2-字符串常用方法

17、isalpha()

如果字符串至少有一个字符并且所有字符都是字母,则返回 True,否则返回 False。

  1. s = 'python'
  2. print(s.isalpha())
  3. # True
  4. s = '123'
  5. print(s.isalpha())
  6. # False
  7. s = 'python123'
  8. print(s.isalpha())
  9. # False
  10. s = 'python-123'
  11. print(s.isalpha())
  12. # False