[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Lovepython015/Python/master/Article/PythonBasis/python10/2.md [Back]  [Original]

# (`__new__`)(`__init__`) #

 `__init__(self)` 



```python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

class User(object):
    def __init__(self, name, age):
        self.name = name;
        self.age = age;

user=User('',23)
```



`__new__` , `__init__` .`__new__` , `__init__`  pickle.load  `__init__` 

![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-14-Python%E7%B1%BB%E5%88%9B%E5%BB%BA%E7%9A%84%E8%BF%87%E7%A8%8B.png)

`def __new__(cls)`  `def __init__(self)` `__new__`  `__init__`   `None` 



```python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

class User(object):
    def __new__(cls, *args, **kwargs):
        #  __new__
        print(' def __new__ ')
        print(args)
        # 
        return super(User, cls).__new__(cls)

    def __init__(self, name, age):
        print(' def __init__ ')
        self.name = name
        self.age = age


if __name__ == '__main__':
    usr = User('', 23)
```



```txt
 def __new__ 
('', 23)
 def __init__ 
```

 `__new__`  `__init__` 

 `__new__`  `__new__`  `metaclass`()

 `__del__`  Python 



Web Proxy Viewer  |  New URL  |  Original Page