Chinaunix首页 | 论坛 | 博客
  • 博客访问: 389897
  • 博文数量: 199
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1530
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 08:43
文章分类

全部博文(199)

文章存档

2015年(101)

2014年(97)

2011年(1)

分类: Python/Ruby

2015-07-22 16:14:24

# -*- coding: UTF-8 -*- 
# Filename :判断字符串   
def is_number(s): 
    try: 
        float(s) 
        return True  
    except ValueError: 
        pass   
    try: 
        import unicodedata
         unicodedata.numeric(s) 
        return True  
    except (TypeError, ValueError): 
        pass   
    return False  
# 测试字符串和数字 
print(is_number('foo')) # False 
print(is_number('1')) # True 
print(is_number('1.3')) # True 
print(is_number('-1.37')) # True 
print(is_number('1e3')) # True  
# 测试 Unicode 
# 阿拉伯语 5 
print(is_number('?')) # False 
# 泰语 2 
print(is_number('?')) # False 
# 中文数字 
print(is_number('四')) # False 
# 版权号 print(is_number('©')) # False

阅读(635) | 评论(0) | 转发(0) |
0

上一篇:if

下一篇:判断奇数偶数

给主人留下些什么吧!~~