I am a beginner to python and want to understand the python class modules and class variables.
I just want to assign a class function's return value to the class variable. I tried in different ways, are these valid in python?
Sample code:
class Example():
def class_member(self):
dict_1 = {'k1' : 'v1','k2' : 'v2'}
return dict_1
class_var = class_member()
print(class_var)
x_obj = Example()
Errors:
class_var = class_member()
TypeError: class_member() takes exactly 1 argument (0 given)
class_var = class_member(self)
NameError: name 'self' is not defined
class_var = Example.class_member()
NameError: name 'Example' is not defined
__init__method that will doself.var = self.method().class_var=x_obj.class_member()?