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

#  #


## 1 ##





![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-09-071102.png)

 `a = ClassA()`  `__init__(self)` 

** `__init__(self)`  **

 `init` `__init__()`  `self`



```python
def __init__(self,[...):
```




![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-09-073421.png)


## 2 ##





```python
def __del__(self,[...):
```




![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-09-084417.png)


## 3Python  ##

Python  

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

# 
class OldClass:
    pass

# 
class NewClass(object):
    pass

```

`object`  Python2  Python3  Python3 





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

# 
class OldClass:
    def __init__(self, account, name):
        self.account = account
        self.name = name


# 
class NewClass(object):
    def __init__(self, account, name):
        self.account = account
        self.name = name


if __name__ == '__main__':
    old_class = OldClass(111111, 'OldClass')
    print(old_class)
    print(type(old_class))
    print(dir(old_class))
    print('\n')
    new_class = NewClass(222222, 'NewClass')
    print(new_class)
    print(type(new_class))
    print(dir(new_class))

```

 python 2.7 

```
/Users/twowater/dev/python/test/venv/bin/python /Users/twowater/dev/python/test/com/twowater/test.py


['__doc__', '__init__', '__module__', 'account', 'name']


['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'account', 'name']

Process finished with exit code 0

```

 Python 3.6 

```
/usr/local/bin/python3.6 /Users/twowater/dev/python/test/com/twowater/test.py


['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'account', 'name']


['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'account', 'name']

Process finished with exit code 0

```


Pyhton3 Python3 



Web Proxy Viewer  |  New URL  |  Original Page