class instantiation uses function notation just pretend that the class object is parameterless function that returns new instance of the class for example (assuming the above class) myclass(creates new instance of the class and assigns this object to the local variable the instantiation operation ("callinga class objectcreates an empty object many classes like to create objects with instances customized to specific initial state therefore class may define special method named __init__()like thisdef __init__(self)self data [when class defines an __init__(methodclass instantiation automatically invokes __init__(for the newly-created class instance so in this examplea newinitialized instance can be obtained byx myclass(of coursethe __init__(method may have arguments for greater flexibility in that casearguments given to the class instantiation operator are passed on to __init__(for exampleclass complexdef __init__(selfrealpartimagpart)self realpart self imagpart complex( - rx ( - instance objects now what can we do with instance objectsthe only operations understood by instance objects are attribute references there are two kinds of valid attribute namesdata attributes and methods data attributes correspond to "instance variablesin smalltalkand to "data membersin +data attributes need not be declaredlike local variablesthey spring into existence when they are first assigned to for exampleif is the instance of myclass created abovethe following piece of code will print the value without leaving tracex counter while counter counter counter print( counterdel counter the other kind of instance attribute reference is method method is function that "belongs toan object (in pythonthe term method is not unique to class instancesother object types can have methods as well for examplelist objects have methods called appendinsertremovesortand so on howeverin the following discussionwe'll use the term method exclusively to mean methods of class instance objectsunless explicitly stated otherwise valid method names of an instance object depend on its class by definitionall attributes of class that are function objects define corresponding methods of its instances so in our examplex is valid method referencesince myclass is functionbut is notsince myclass is not but is not the same thing as myclass -it is method objectnot function object first look at classes