I need to learn about the using variables on function in same class.
For example my class is like in below:
class MainWindow(QMainWindow):
def __init__(self,parent = None):
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def myFunc1(self):
self.myVariable = 5
def myFunc2(self):
print(self.myVariable) #gives me 5
When I defined to variable like self.myVariable in myFunc1 I get its value from myFunc2. So If I use the self.does that make it a global variable ?
If I use like local variable in function, should i use it without self ?
selfis not a global variable, but tied to the class (instance). In fact,selfrefers directly to the class instance. Any variable set withself.myVariableand the like, are therefore tied to the class instance. They are not local to the class method, nor global (to the script or module), but tied to the class instance.