推荐学习书目
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
tanteng
V2EX  ›  Python

Python 的构造函数是__init__吧?

  •  
  •   tanteng ·
    tanteng · May 8, 2015 · 3790 views
    This topic created in 4049 days ago, the information mentioned may be changed or developed.


    这个教程说init不是python构造函数,请各位专家大神说说。
    11 replies    2015-05-21 13:20:30 +08:00
    thinker3
        1
    thinker3  
       May 8, 2015
    __new__, metaclass
    vinceguo
        2
    vinceguo  
       May 8, 2015
    python magic function, google
    staticor
        3
    staticor  
       May 8, 2015
    我个人理解是

    new: 你在内存的空间中找到一块空地, 先打个标签: 这地我占了.
    init : 你逛了一会儿 回到刚刚占的地, 开始盖了一房子, 用到的材料有 xxx xxx.

    所以若是说 **构造** , 应该侧重于前者的功能.
    rcmerci
        4
    rcmerci  
       May 8, 2015
    1. __new__
    2. 实例构造完成
    3. __init__ (初始化一些东西)
    lilydjwg
        5
    lilydjwg  
       May 8, 2015
    __new__ 才是构造方法,__init__ 是初始化方法。
    iEverX
        6
    iEverX  
       May 8, 2015
    感觉C#或者Java的构造函数,是 __new__ 和 __init__ 两个合起来
    monkeylyf
        7
    monkeylyf  
       May 8, 2015
    __init__是初始化 在执行这个的时候 实例已经被创建了 这和传统的constructor的概念是不一样的 (参考__new__)
    joshryo
        8
    joshryo  
       May 9, 2015
    python里面很多__xxx__方法都是很玄妙的东西,表面看着执行某函数/操作,其实后面都是执行的某个__xxx__方法
    slideclick
        9
    slideclick  
       May 20, 2015
    记住PPT内容,不要抠字眼。
    slideclick
        10
    slideclick  
       May 21, 2015
    你这ppt不错,哪里找的?
    tanteng
        11
    tanteng  
    OP
       May 21, 2015
    @slideclick 不是ppt,是我截图网页内容
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3162 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 261ms · UTC 13:56 · PVG 21:56 · LAX 06:56 · JFK 09:56
    ♥ Do have faith in what you're doing.