Everything you put inside a function is local to this function, you can not use elsewhere. There are some solutions.
The first is to return the value - but not the variable - you want, and then whoever calls the function can "capture" that value and do what you want.
Or you must create a variable in another location that can be used within the function. In this case there can be two alternatives. Some types of variables may have their value passed to the function as argument and the function updates the received parameter, when the function returns, the variable that had this value before the call will have the value placed inside the function.
The most common in these cases is to create a class that contains variables that are present in the class, then all functions within the class will have access to these class variables, so any change in it within a function will reflect to all other.
For very simple examples, and only in these cases, it is possible to declare the variable outside the function and it will be accessed by all functions. This is the equivalent of what you do with classes. But with classes you have a scope defined and does not cause confusion. In a very simple code that will not be used in a complex system, ie in a code of script even, you can use without any confusion, but in other situations you should not use this form.
These two concepts of using variables outside the function are more advanced and I think we should not try now that it still does not dominate the basic functioning of functions. For now just put a return:
def Luggage():
mala = []
take = raw_input("O que você deseja levar na sua viagem?")
mala.append(take)
return mala
Calling:
x = Luggage()
print(x)
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.
Did the answer solve the problem? Do you think you can accept one of them? See [tour] how to do this. You’d be helping the community by identifying the best solution. You can only accept one of them, but you can vote for anything on the entire site.
– Maniero