Why it is not printing ??
Actually, I am a python beginner and I was learning stacks in python and got stuck here HOW TO FIX IT ??
text = ""
def func():
stack=["asd", "qwe"]
text=stack[1]
text=text+stack[0]
func()
print(text)
Why it is not printing ??
Actually, I am a python beginner and I was learning stacks in python and got stuck here HOW TO FIX IT ??
text = ""
def func():
stack=["asd", "qwe"]
text=stack[1]
text=text+stack[0]
func()
print(text)
when you are defining a function the variable inside the function is not accessible to the outside of the function so you have to return the variable you want to update. u can use print(func())
or text=func()
or print(text)
text = ""
def func():
stack=["asd", "qwe"]
text=stack[1]
text=text+stack[0]
return text
text=func()
print(text)
output
qweasd