[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/magic-coder/Python/master/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__` 

![Python](http://upload-images.jianshu.io/upload_images/2136918-a2b39b078cc81841?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

`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