Can attributes be assigned anywhere within a class?
Can attributes be assigned anywhere within a class? If so, how do scope
rules works for each of the following cases?
class GreatComposers(object):
def __init__(self, name, birthday, instrument):
# attributes assigned in __init__
self.name = name
self.birthday = birthday
self.instrument = instrument
def setFullName(self)
# attributes assigned in other class methods
self.fullname = self.name + self.birthday
self.job = self.instrument + 'ist'
# attributes assigned outside any functions
self.nationality = 'german'
No comments:
Post a Comment