what is the difference between name and _name?
Frank Millman
frank at chagford.com
Wed Aug 20 08:18:18 EDT 2014
"luofeiyu" <elearn2014 at gmail.com> wrote in message
news:53F48957.8020700 at gmail.com...
> So in this example:
>>> class Person(object):
>>> def __init__(self, name):
>>> self._name = name
>> [...]
>>> name = property(getName, setName, delName, "name property docs")
>>
>>
>> (3) name is the public attribute that other classes or functions are
>> permitted to use.
>>
>>
>> problem 1: there is no self.name = something in the defination ,why i
>> can get bob.name?
>>
>>
I also found it confusing at first, but reading the docs and trying out the
examples at the interpreter prompt helped a lot.
Here is the relevant doc page -
https://docs.python.org/3/library/functions.html#property
If you really want to know what goes on under the hood, Google turned up
this in-depth explanation -
http://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work
HTH
Frank Millman
More information about the Python-list
mailing list