在Python中判断字符为数字还是字母

来源:互联网 发布:微信ubuntu版 编辑:程序博客网 时间:2024/05/19 20:58

在Python中判断字符为数字还是字母的方法及示例:

>>> c ='a' 

>>>c 
'a' 
>>>type(c) 
 
>>>c.isalpha() 
True 
>>>c.isdigit() 
False

 

>>> n =‘2’ 
>>>n 
'2' 
>>>type(n) 
 
>>>n.isalpha() 
False 
>>>n.isdigit() 
True