(July 3, 2016 at 8:16 am)SteelCurtain Wrote: Ahh, I see what you mean.
You want to just initialize variables.
I think Python only allows you to do that with lists and tuples.
No, you can initialize variables with Python. What you did inside the procedure/function in Python code (a = 5) was an example of initializing, right?
Anyway, I can't remember why I wished variables in Python could just be declared/defined without initial assignment, but I did just learn something new in Python. Apparently, you can test for whether or not a variable has been defined using globals() or locals().
For example:
Code:
v = 0
if 'v' not in globals():
print 'v not defined'
else:
print 'v defined'
It won't throw an error at you for not defining v if you didn't. But note that you have to wrap quotes around the 'v' for this to run without errors.