If the variable is entered like a string (e.g. '2010'
):
if variable and variable.isdigit():
return variable #or whatever you want to do with it.
else:
return "Error" #or whatever you want to do with it.
Before using this I worked it out with try/except
and checking for (int(variable))
, but it was longer code. I wonder if there's any difference in use of resources or speed.