python - Can attributes be assigned anywhere within a class? -


can attributes assigned anywhere within class? if so, how scope rules works each of 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 functions     self.nationality = 'german' 

no, doesn't work @ class scope (self.nationality = 'german' in example), there no name self in scope @ point. , doesn't work in other cases because methods or self parameter somehow special. attributes can assigned anywhere have reference object. includes methods, other code has access object in question.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -