Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Boolean Wont Work
#4
You've been bitten by the 'global feature' of Python. The following code will demonstrate one way to fix your problem.
def myFunction():
    p = True
    return

def myFunction2():
    global p
    p = True
    return

def myFunction3(p):
    p = True
    return p

p = False
myFunction()
print("p after myFunction = {}.".format(p))

p = False
myFunction2()
print("p after myFunction2 = {}.".format(p))

p = False
p = myFunction3(p)
print("p after myFunction3 = {}.".format(p))
Output:
p after myFunction = False. p after myFunction2 = True. p after myFunction3 = True.
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Messages In This Thread
Boolean Wont Work - by fierygaming - Jun-13-2018, 04:12 PM
RE: Boolean Wont Work - by volcano63 - Jun-13-2018, 04:42 PM
RE: Boolean Wont Work - by fierygaming - Jun-13-2018, 04:56 PM
RE: Boolean Wont Work - by ljmetzger - Jun-13-2018, 05:02 PM
RE: Boolean Wont Work - by fierygaming - Jun-13-2018, 05:18 PM
RE: Boolean Wont Work - by fierygaming - Jun-13-2018, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why wont this path work one way, but will the other way? cubangt 2 696 Sep-01-2023, 04:14 PM
Last Post: cubangt
  Why wont subprocess call work? steve_shambles 3 2,717 Apr-28-2020, 03:06 PM
Last Post: steve_shambles
  When I import a Module it wont run PyNovice 17 6,568 Oct-26-2019, 11:14 AM
Last Post: PyNovice
  Why wont this work? ejected 2 3,245 Mar-29-2019, 05:33 AM
Last Post: snippsat
  wont print last sentence.. mitmit293 2 2,429 Jan-27-2019, 05:38 PM
Last Post: aakashjha001
  Why wont this work :( Nonagon 2 3,052 Nov-03-2018, 03:38 AM
Last Post: wavic
  Reddit Bot comes up with no errors but wont actually run Rubix3D 0 2,645 Jan-12-2018, 12:53 AM
Last Post: Rubix3D

Forum Jump:

User Panel Messages

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