Home > Back-end >  useing a variable in a another function inside a Class
useing a variable in a another function inside a Class

Time:03-14

I want to use a variable in different function in a class. Here is a simple code:

Class Simple:
    def__init__(self):
       pass

    
    def func1(self)
        a = [1,2,3]

    def func2(self)
        b = a
        print(b)

How can ı use this "a" variable inside of func2 ?

CodePudding user response:

As Johnny Mopp said in his comment, you can make an instance variable.

Class Simple:
    def__init__(self):
       pass
    
    def func1(self):
        self.a = [1,2,3]

    def func2(self);
        print(self.a)
  • Related