Discuss / Python / self._width 和self.__width 的区别

self._width 和self.__width 的区别

Topic source

哦哟你哟

#1 Created at ... [Delete] [Delete and Lock User]

私有变量不是前面两个下划线吗,代码中为什么是一个,而且运行的时候变量前面加一个和两个下划线都运行成功了,所以想问下大佬他们有什么区别吗

Freddiemars

#2 Created at ... [Delete] [Delete and Lock User]

加一个是为了区别原来变量的名字,你叫它width123和height123也可以,要是你直接return width就会出现RecursionError: maximum recursion depth exceeded

哦哟你哟

#3 Created at ... [Delete] [Delete and Lock User]

好的好的 谢谢


  • 1

Reply