0
How to call a function with one str argument and use that str as a variable to access a variable present inside a class.
Please check the attached code https://code.sololearn.com/cQPRaiR41s3B/?ref=app
1 ответ
0
You can assign it to the class variable as shown below. You can interact with the passed variable and the object variable by using “self” or not using “self”.
class MyClass:
a = 0
b = 5
def classfun(self, a):
self.a = a
print (self.b * a)
obj = MyClass()
obj.classfun(10)