Jay Taylor's notes
back to listing indexpython - What is the meaning of single and double underscore before an object name? - Stack Overflow
[web search]
Original source (stackoverflow.com)
Clipped on: 2023-11-01
-
4A great short answer from another thread: stackoverflow.com/a/8689983/911945 Dec 3, 2017 at 8:33
-
See also this excellent answer here, which discusses single vs double leading underscores, and demonstrates "name mangling"!: Answer to "Private members in Python" Mar 22, 2021 at 23:53
-
but how about if "__a" was a class variable, then you cannot access it even with the instructions from python docs.. Jul 6, 2017 at 7:07
-
Please can you update your answer with an example of double underscore with respect to inheritence?– variableSep 9, 2019 at 15:56
-
1
._variable
, according to the posts above and PEP-8, is not only a convention: "from M import *
does not import objects whose names start with an underscore.". However, in the presented case showing it as a class attribute, it doesn't change anything.– pdaawrMay 3, 2021 at 9:07
-
2After editing this answer myself, I prefer stackoverflow.com/a/8689983/1048186 Aug 21, 2018 at 19:30
-
What do you mean by "As we have seen, A.test() didn't call B.__test() methods" - where have you called A.test()?– variableSep 9, 2019 at 15:27
-