Using variables from other functions in Python -
i learning python , writing simple program has divided functions. problem have 1 function should return strings 4 different variables, should used in function.
e.g.
def function1(): var1 = input("write something: ") var2 = input("write something: ") var3 = input("write something: ") def function2(): print(var1) print(var2) print(var3) function1() function2()
this gives error message since var1 not defined in frame of function2. how should solved? illustration simplified clarity, post more specific if required.
return variables in function1
:
def function1(): var1 = input("write something: ") var2 = input("write something: ") var3 = input("write something: ") return var1, var2, var3
and make them arguments in function2
:
def function2(var1, var2, var3): print(var1) print(var2) print(var3)
call them this:
var1, var2, var3 = function1() function2(var1, var2, var3)
Comments
Post a Comment