Python Forum
saving a true/false of a single value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
saving a true/false of a single value
#1
i often have statements like:
    fail = result < 0
to save true/false from a conditional until later, when the test can't readily be done again and/or the relevant variables may ha been changed. or there may be a variety of different tests for a common end result. today i was wanting to this for the truthfulness of a variable's value instead of an expression. the code today is:
    doargs = True if ptargs else False
in the above code ptargs is initialized to be an empty list and may have arguments appended to it. but the logic that depends on doargs (to decide whether to use the arguments or read input) is in a loop where that list gets changed or cleared. making a copy of it seems wasteful (although i'm sure i have enough memory for it) and all i need is its true/false, hence the way i set doargs. is there a better/simpler way to do this? would this work?
   doargs = not not ptargs
or is what i have, now, the best way to go?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
I tend to use bool(ptargs).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
do you also use it around expressions that are clearly boolean?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Why would I?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between «1 in [2] == False» and «(1 in [2]) == False» fbaldit 2 2,221 Apr-20-2020, 05:39 PM
Last Post: fbaldit
  Do break operators turn while loop conditions from True to False? Drone4four 5 2,933 Oct-24-2019, 07:11 PM
Last Post: newbieAuggie2019
  Returning True or False vs. True or None trevorkavanaugh 6 9,216 Apr-04-2019, 08:42 AM
Last Post: DeaD_EyE
  Returning true or false in a for loop bbop1232012 3 8,110 Nov-22-2018, 04:44 PM
Last Post: bbop1232012
  True == not False Skaperen 6 3,904 Aug-23-2018, 10:26 AM
Last Post: DeaD_EyE
  Get True of false outside a loop morgandebray 2 2,446 Aug-09-2018, 12:39 PM
Last Post: morgandebray
  True or false if running something? Artdigy 4 3,399 Mar-27-2018, 05:50 PM
Last Post: nilamo
  True vs False Skaperen 10 7,596 Jun-14-2017, 09:56 AM
Last Post: wavic
  How to turn variable true and false using function? hsunteik 5 6,477 Feb-20-2017, 11:44 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

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