Python Forum
How to turn variable true and false using function?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to turn variable true and false using function?
#4
You can't because Boolean variables are immutable. If you need a function to change the value variable, use a return statement, and assign the return value to the variable.

def longerThatFive(s):
   return len(s)>5

t1=longerThanFive('abc')
t2=longerThanFive('abcdef')

print t1,t2
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
RE: How to turn variable true and false using function? - by Ofnuts - Feb-18-2017, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 560 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  gpiozero button turn off LED that is already on duckredbeard 3 838 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  Exceeding the value - turn on the relay. stsxbel 0 582 May-27-2024, 07:18 PM
Last Post: stsxbel
  Variable for the value element in the index function?? Learner1 8 2,919 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 1,602 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 7,376 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 2,140 Aug-07-2023, 05:58 PM
Last Post: Karp
  If function is false search next file mattbatt84 2 1,944 Sep-04-2022, 01:56 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,803 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 2,930 Feb-09-2022, 10:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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