[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/huanpython/Python/master/Article/python9/4.md [Back]  [Original]

#  #

## 1 ##





|  |  |
| ------| ------ |
|`__init__` ||
|`__del__ `| |
|`__repr__ `| |
|`__setitem__ `| |
|`__getitem__`| |
|`__len__`| |
|`__cmp__`| |
|`__call__`| |
|`__add__`| |
|`__sub__`| |
|`__mul__`||
|`__div__`| |
|`__mod__`| |
|`__pow__`||



* `type(obj)`
* `isinstance(obj, type)` type 
* `hasattr(obj, attr)`/
* `getattr(obj, attr[, default])` /,  default  default AttributeError 
* `setattr(obj, attr, value)`/ obj.attr=value
* `dir(obj)`

## 2 ##

 Python 



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

class User(object):
    def upgrade(self):
        pass

    def _buy_equipment(self):
        pass

    def __pk(self):
        pass

```

## 3 ##


* **@classmethod**


* **@property**




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

class UserInfo(object):
    lv = 5

    def __init__(self, name, age, account):
        self.name = name
        self._age = age
        self.__account = account

    def get_account(self):
        return self.__account

    @classmethod
    def get_name(cls):
        return cls.lv

    @property
    def get_age(self):
        return self._age


if __name__ == '__main__':
    userInfo = UserInfo('', 23, 347073565);
    # 
    print(dir(userInfo))
    # 
    print(userInfo.__dict__)
    # 
    print(UserInfo.lv)
    # get_age
    print(userInfo.get_age)
```



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

Web Proxy Viewer  |  New URL  |  Original Page