您可以使用
str.isdigit和
str.isalpha:
if a.isalpha(): #do somethingelif a.isdigit(): #do something
帮助
str.isdigit:
>>> print str.isdigit.__doc__S.isdigit() -> boolReturn True if all characters in S are digitsand there is at least one character in S, False otherwise.
帮助
str.isalpha:
>>> print str.isalpha.__doc__S.isalpha() -> boolReturn True if all characters in S are alphabeticand there is at least one character in S, False otherwise.



