0

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)
Adhun Thalekkara
  • 713
  • 10
  • 23
  • 2
    Does this answer your question? [changing global variables within a function in python](https://stackoverflow.com/questions/51564669/changing-global-variables-within-a-function-in-python) – dibery Aug 08 '20 at 08:17

1 Answers1

1

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
Adhun Thalekkara
  • 713
  • 10
  • 23