in codewe could decide to change the set_name(method as followsdef set_name(selfname)if not nameraise exception("invalid name"self _name name nowin java and similar languagesif we had written our original code to do direct attribute accessand then later changed it to method like the preceding onewe' have problemanyone who had written code that accessed the attribute directly would now have to access the method if they don' change the access style from attribute access to function calltheir code will be broken the mantra in these languages is that we should never make public members private this doesn' make much sense in python since there isn' any real concept of private memberspython gives us the property keyword to make methods look like attributes we can therefore write our code to use direct member accessand if we unexpectedly need to alter the implementation to do some calculation when getting or setting that attribute' valuewe can do so without changing the interface let' see how it looksclass colordef __init__(selfrgb_valuename)self rgb_value rgb_value self _name name def _set_name(selfname)if not nameraise exception("invalid name"self _name name def _get_name(self)return self _name name property(_get_name_set_nameif we had started with the earlier non-method-based classwhich set the name attribute directlywe could later change the code to look like the preceding one we first change the name attribute into (semi-private _name attribute then we add two more (semi-private methods to get and set that variabledoing our validation when we set it