V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lm902
V2EX  ›  Python

Python 中如何判断一个值是否能被 Parse

  •  
  •   lm902 ·
    lm902 · 2014-05-27 20:32:27 +08:00 · 3503 次点击
    这是一个创建于 3620 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如C#中int.Parse("2")返回2,int.TryParse("2")返回true,int.Parse("a")抛出异常,int.TryParse("a")返回false而不会抛出异常

    我想知道Python中有哪个方法是类似于上面所说int.TryParse的,找半天没找到
    aec4d
        1
    aec4d  
       2014-05-27 21:36:02 +08:00
    isinstance(2,int),不抛出异常捕获异常处理就可以
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1149 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:01 · PVG 07:01 · LAX 16:01 · JFK 19:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.