May-06-2019, 08:34 PM
(May-06-2019, 12:17 AM)jsoberano Wrote:Don't useif flag is 1: return True else: return False
is
like that. It should only be used to check for object identity, such as something is None
. flag is 1
will not work on all versions of python, and only works on cpython because small integers are cached instead of reused (ie: please don't rely on implementation details). More generally, if you CAN use ==
, then you SHOULD use ==
.Also, that whole if statement at the end can just be replaced with
return flag == 1
. Or, more simply, as just return flag
, since it'll only ever be 1 or 0.Also, because
flag
only ever has two values, and those values imply on/off or yes/no or good/bad, it should be a bool with a value of either True or False, instead of 1/0.