Python Forum
Need help and suggestions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help and suggestions
#3
(May-06-2019, 12:17 AM)jsoberano Wrote:
    if flag is 1:
        return True
    else:
        return False
Don't use 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.
Reply


Messages In This Thread
Need help and suggestions - by jsoberano - May-06-2019, 12:17 AM
RE: Need help and suggestions - by Yoriz - May-06-2019, 12:23 AM
RE: Need help and suggestions - by nilamo - May-06-2019, 08:34 PM
RE: Need help and suggestions - by michalmonday - May-07-2019, 03:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Suggestions on my code YorgosTheProgramer 2 3,463 Mar-13-2017, 01:22 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020