Created
April 13, 2014 19:56
-
-
Save deontologician/10599769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog(object): | |
def __init__(self): | |
self.dict_ = {} | |
self.__dict__ | |
def add(self, name, breed): | |
self.dict_[name] = breed | |
def __repr__(self): | |
return 'Dog({}, {})'.format(*self.dict_.items()) | |
class Dog(object): | |
def add(self, name, breed): | |
self.__dict__['name'] = name | |
self.__dict__['breed'] = breed | |
def __repr__(self): | |
return 'Dog({}, {})'.format(self.__dict__['name'], | |
self.__dict__['breed']) | |
>>> dog = Dog() | |
>>> dog.add('Fido', 'Mastiff') | |
>>> dog.name | |
'Fido' | |
>>> dog.breed | |
'Mastiff' | |
class Dog(object): | |
def __init__(self, name, breed): | |
self.name = name | |
self.breed = breed | |
def __repr__(self): | |
return 'Dog({}, {})'.format(self.name, self.breed) | |
>>> dog = Dog('Fido', 'Mastiff') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment