Python中_,__,__xx__的区别

_xx 单下划线开头

Python中没有真正的私有属性或方法,可以在你想声明为私有的方法和属性前加上单下划线,以提示该属性和方法不应在外部调用.如果真的调用了也不会出错,但不符合规范.

 

__xx 双下划线开头

双下划线开头,是为了不让子类重写该属性方法.通过类的实例化时自动转换,在类中的双下划线开头的属性方法前加上”_类名”实现.

__xx__

此种写法为python内建属性方法,最好不要在外部调用

 

 

参考自:http://blog.csdn.net/wukai_std/article/details/54972522

posted @ 2017-09-05 20:43  云中摆渡的老船长  阅读(267)  评论(0)    收藏  举报

It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things