How to call a function with one str argument and use that str as a variable to access a variable present inside a class. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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

26th Apr 2021, 6:16 PM
Abhishek Kumar
Abhishek Kumar - avatar
1 Resposta
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)
26th Apr 2021, 9:11 PM
Jerry Hobby
Jerry Hobby - avatar