Do you guys really tell me to transfer a variable from a function to another python function? Example:
def Func1(){ var1 = 'data' } def Func2(){ print (var1) } Is it possible to implement such a thing as something without global variables?
Do you guys really tell me to transfer a variable from a function to another python function? Example:
def Func1(){ var1 = 'data' } def Func2(){ print (var1) } Is it possible to implement such a thing as something without global variables?
To pass an argument to another function, it must at least take it. You can call the second from the first function with the desired argument.
def Func1(): var1 = 'data' Func2(var1) def Func2(var1): print(var1) Func1() The first function can also return a value using return. This value can be immediately transferred to the call of the second function without creating global variables.
def Func1(): var1 = 'data' return var1 def Func2(var1): print(var1) Func2(Func1()) PS In Python, indentation is used instead of operator brackets.
Source: https://ru.stackoverflow.com/questions/632028/
All Articles