Creating a Class (Class Definition) : Class Definition : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Class Definition »

 

Creating a Class (Class Definition)


class AddrBookEntry(object):           
    def __init__(self, nm, ph):        
        self.name = nm                 
        self.phone = ph                
        print 'Created instance for:', self.name
    def updatePhone(self, newph):      
        self.phone = newph
        print 'Updated phone# for:', self.name

john = AddrBookEntry('A''000-555-1212')
jane = AddrBookEntry('B''111-555-1212')
print john
print john.name
print john.phone
print jane.name
print jane.phone

john.updatePhone('111-555-1212')
print john.phone



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Class Definition