[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/coding336/Python/master/python9/2.md [Back]  [Original]

#  #

## 1 ##



```python
class ClassName:
    
    .
    .
    .
    
```





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

 __init__()  __init__() 





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

,  self

 self 



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

class Test:
    def prt(self):
        print(self)
        print(self.__class__)

t = Test()
t.prt()
```



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

self  `self.__class__` 

 self  python  self

## 2Python  ##

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))

```


Pyhton3 Python3 

Web Proxy Viewer  |  New URL  |  Original Page