What is Pythonic for using private variables?

I recently posted a stackoverflow question and got permission.

Someone offered me a coding style, and I did not get any additional input. I have the following question with a link to a previous request.

  • How can we declare private variables inside a class in python? I thought using double underscore (__) to treat a variable as confidential. Please correct me.

  • As suggested earlier, we don’t need to use the getter or setter method. Shouldn't we use a getter or setter, or both? Please let me know your suggestion about this.

+5
source share
5 answers

Python public, __ - , , .

, , public , .

Idiomatic Python get/set accessors, , private.

, -, , - __ .

, , -, , , , , , Python 20 , .

+8

PEP 8 (http://www.python.org/dev/peps/pep-0008/) " ", .

:

" "private",      Python ( ).

:

" ,        ,        ."

, .

Update:

(, ). - . - python pythonic.

+4

:

, , python. , , . "".

Getter/:

, , 'private'. , , . , getter/setter.

0
0

All Articles