print die getvalue( the call to the constructor sets the instance variable die value to the next line prints out this value the value set by the constructor persists as part of the objecteven though the constructor is over and done with similarlyexecuting die setvalue( changes the object by setting its value to when the object is asked for its value the next timeit responds with that' just about all there is to know about defining new classes in python now it' time to put this new knowledge to use examplethe projectile class returning to the cannonball examplewe want class that can represent projectiles this class will need constructor to initialize instance variablesan update method to change the state of the projectileand getx and gety methods so that we can find the current position let' start with the constructor in the main programwe will create cannonball from the initial anglevelocity and height cball projectile(anglevelh the projectile class must have an __init__ method that uses these values to initialize the instance variables of cball but what should the instance variables beof coursethey will be the four pieces of information that characterize the flight of the cannonballxposyposxveland yvel we will calculate these values using the same formulas that were in the original program here is how our class looks with the constructorclass projectiledef __init__(selfanglevelocityheight)self xpos self ypos height theta math radians(angleself xvel velocity math cos(thetaself yvel velocity math sin(thetanotice how we have created four instance variables inside the object using the self dot notation the value of theta is not needed after __init__ terminatesso it is just normal (localfunction variable the methods for accessing the position of our projectiles are straightforwardthe current position is given by the instance variables xpos and ypos we just need couple of methods that return these values def getx(self)return self xpos