推荐学习书目
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 · May 27, 2014 · 4141 views
    This topic created in 4393 days ago, the information mentioned may be changed or developed.
    例如C#中int.Parse("2")返回2,int.TryParse("2")返回true,int.Parse("a")抛出异常,int.TryParse("a")返回false而不会抛出异常

    我想知道Python中有哪个方法是类似于上面所说int.TryParse的,找半天没找到
    aec4d
        1
    aec4d  
       May 27, 2014
    isinstance(2,int),不抛出异常捕获异常处理就可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1128 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:09 · PVG 02:09 · LAX 11:09 · JFK 14:09
    ♥ Do have faith in what you're doing.