I would pass a variable between two def inside a function. How can i do? i tried using global but didn’t work
class example:
def funz1(self,q,b):
global queue
queue = []
queue += [q]
queue += [a]
def funz2(self):
return str(queue.pop())
but it said me that queue is an empty list
You have to use the
selfparameter, which points to theexampleinstance itself:Read more here.
Also, as a side note,
array += [item]is wrong, you should usearray.append(item)