I'm trying to print an array in python this way:
ord = []
def printTest():
global ord
print ', '.join(ord)
def main():
ord = ["a","b"]
printTest()
main()
But it prints only a new line empty. How can I solve this?
Thanks!!
global means that future assignments to this variable will be in the global scope. When you just use ord in printTruthTable(), you don't need to say global because the global scope is already checked when you refer to a variable. When you assign ord, however, you need to say that we are creating a global variable, not a local variable. Therefore, move global ord from printTruthTable() to main(). On the side, ord is a bad name because it shadows the built-in function. Also, global variables are almost never needed. In this case, just pass ord as an argument instead.
printTruthTable!