Is it possible to declare a variable in Python, like so?:
var
so that it initialized to None? It seems like Python allows this, but as soon as you access it, it crashes. Is this possible? If not, why?
EDIT: I want to do this for cases like this:
value
for index in sequence:
if value == None and conditionMet:
value = index
break
Duplicate
- Uninitialised value in python (by same author)
- Are there any declaration keywords in Python? (by the same author)
It is a good question and unfortunately bad answers as
var = None
is already assigning a value, and if your script runs multiple times it is overwritten withNone
every time.It is not the same as defining without assignment. I am still trying to figure out how to bypass this issue.