useing a variable in a another function inside a Class

Question:

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 ?

Asked By: Selman

||

Answers:

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)
Answered By: Shib
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.