On Mon, May 31, 2021 at 2:58 AM Irv Kalb <i...@furrypants.com> wrote: > > I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. > > I understand what a "property" is, how it is used and the benefits, but > apparently my explanation hasn't made the light bulb go on for my editor. > The editor is asking for a definition of property. I've looked at many > articles on line and a number of books, and I haven't found an appropriate > one yet. > > I have written some good examples of how it works, but I agree that a > definition up front would be helpful. I have tried a number of times, but my > attempts to define it have not been clear. Perhaps the best I've found so > far is from the Python documentation: > > A property object has getter, setter, and deleter methods usable as > decorators that create a copy of the property with the corresponding accessor > function set to the decorated function. > > But I'm hoping that someone here can give me a more concise (one or two > sentence) definition of the word "property". >
A property is an attribute with customized get/set behaviour. It lets you change what normally happens when you say "print(thing.attribute)" or "thing.attribute = spam". Personally, I wouldn't bother mentioning deletion in the opening definition, for brevity's sake, but it'll be there when you go into detail. ChrisA -- https://mail.python.org/mailman/listinfo/python-list