Hello i need print mystring inside "functionone" from another function and i did this:
def functionone():
mystring = "This word from functionone!"
def functiontwo():
print(mystring)
But it doesn’t work. How i can do this correctly?
>Solution :
def functionone():
return "This word from functionone!"
def functiontwo():
print(functionone())
Or even:
def functionone():
return "This word from functionone!"
def functiontwo(msg):
print(msg)
functiontwo( functionone() )
You CAN do what you ask using globals, but this is poor practice and leads to difficult-to-find errors.
def functionone():
global mystring
mystring = "This word from functionone!"
def functiontwo():
print(mystring)