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

#  #


## 1 ##

 Java  public   private 

 Python 

 `__private_attrs`  `self.__private_attrs`



 Python 

 Python 



![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-09-Python%20%E5%B1%9E%E6%80%A7%E8%AE%BF%E9%97%AE%E6%8E%A7%E5%88%B6.png)



```python

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

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

    def get_account(self):
        return self.__account


if __name__ == '__main__':
    userInfo = UserInfo('', 23, 347073565);
    # 
    print(dir(userInfo))
    # 
    print(userInfo.__dict__)
    print(userInfo.get_account())
    # 
    print(userInfo._UserInfo__account)


```



![](http://twowaterimage.oss-cn-beijing.aliyuncs.com/2019-10-09-Python%E5%8F%8C%E4%B8%8B%E5%88%92%E7%BA%BF%E5%B1%9E%E6%80%A7.png)


## 2 ##





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


## 3 ##

 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

```



Web Proxy Viewer  |  New URL  |  Original Page