[Tutor] properties beginner M Dawson book

Steven D'Aprano steve at pearwood.info
Sun Jun 10 13:58:37 CEST 2012


Nicholas Harman wrote:

> I have done a little programming in BlueJ Java before but I decided to try
> the “Python style” as explained in the chapter, using properties rather
> than variables and getters and setters ..... My main question is:  When
> using property and setter it seems I must use “__name” or “__volume”
> (Python’s version of private variables).  Is this true?

Certainly not. Python doesn't enforce any naming convention on you. You can 
use any name you like. But you *should* use something like "__name" or 
"__volume", simply because that will be more sensible than most other names. 
But if you choose to use something else, Python won't stop you.

Note: you can also use just a single underscore, _name and _volume, to 
indicate that the attributes are private and should not be touched.


-- 
Steven



More information about the Tutor mailing list