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
Rorschach
V2EX  ›  Python

用 Python 自身如何实现 int()、set()、str()这些工厂函数

  •  
  •   Rorschach · 2015-02-19 23:40:43 +08:00 via Android · 3340 次点击
    这是一个创建于 3374 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    2015-02-20 16:42:15 +08:00
    Melodic
        1
    Melodic  
       2015-02-19 23:48:11 +08:00
    判断类型-->执行 --> 检查类型 --> 返回值
    |
    ->触发异常

    type和isinstance()可以用嘛?
    est
        2
    est  
       2015-02-20 08:45:06 +08:00 via Android
    PyObject里随便撸
    dant
        3
    dant  
       2015-02-20 13:13:10 +08:00 via iPhone
    str(obj) -> obj.__str__()
    geew
        4
    geew  
       2015-02-20 16:42:15 +08:00
    3楼说得很对 python里面 万物皆对象 楼主所说的工厂函数在每个对象里面都有自己的实现
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1634 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:07 · PVG 01:07 · LAX 10:07 · JFK 13:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.