circle circle _replace(radius= just as when we create circlethere is nothing to stop us from (or warn us aboutsetting invalid data if the circles were going to need lots of changeswe might opt to use mutable data type such as listfor the sake of conveniencecircle [ this doesn' give us any protection from putting in invalid dataand the best we can do about accessing elements by name is to create some constants so that we can write things like circle[radius but using list brings additional problems--for examplewe can legitimately call circle sort()using dictionary might be an alternativefor examplecircle dict( = = radius= )but again there is no way to ensure valid radius and no way to prevent inappropriate methods from being called object-oriented concepts and terminology |what we need is some way to package up the data that is needed to represent circleand some way to restrict the methods that can be applied to the data so that only valid operations are possible both of these things can be achieved by creating custom circle data type we will see how to create circle data type in later in this sectionbut first we need to cover some preliminaries and explain some terminology don' worry if the terminology is unfamiliar at firstit will become much clearer once we reach the examples we use the terms classtypeand data type interchangeably in python we can create custom classes that are fully integrated and that can be used just like the built-in data types we have already encountered many classesfor exampledictintand str we use the term objectand occasionally the term instanceto refer to an instance of particular class for example is an int object and "oblongis str object most classes encapsulate both data and the methods that can be applied to that data for examplethe str class holds string of unicode characters as its data and supports methods such as str upper(many classes also support additional featuresfor examplewe can concatenate two strings (or any two sequencesusing the operator and find sequence' length using the built-in len(function such features are provided by special methods--these are like normal methods except that their names always begin and end with two underscoresand are predefined for exampleif we want to create class that supports concatenation using the operator and also the len(functionwe can do so by implementing the __add__(and __len__(special methods in our class converselywe should never define any method with name that begins and ends with two underscores unless it is one of the predefined special methods and is