Python Forum
What's the difference b/w assigning start=None and start=" "
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the difference b/w assigning start=None and start=" "
#1
If both empty strings and None are evaluated as FALSE,then:
start = None
   while start != "":
            start = (input("\nStart: "))
        
         if start:
            start = int(start)
 
            finish = int(input("Finish: "))
            print("word[", start, ":", finish, "] is", end=" ")
            print(word[start:finish])

    input("\n\nPress the enter key to exit.")
In the above code the while loop should evaluate to false and the loop should not be entered in the first place right? But if I run the program it runs fine.(this is a piece of code from Pizza slicer program from the book Python programming for absolute beginners).Where is my understanding messed up?
Reply
#2
None, '', 0, 0.0, empty containers like list, tuple, dict, etc. will be evaluated as False
however None != "" is evaluated as True, because None and "" empty string are not the same
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QThread Signal is emitted immediately at start of Code Caliban86 3 1,958 Sep-26-2024, 02:02 PM
Last Post: deanhystad
  I think I need to delete input data because returning to start fails thelad 2 1,130 Sep-24-2024, 10:12 AM
Last Post: thelad
  ''.join and start:stop:step notation for lists ringgeest11 2 3,921 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Error: can't start new thread maha2 0 2,555 Jun-13-2023, 12:26 PM
Last Post: maha2
  Start print a text after open an async task via button Nietzsche 0 1,186 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Start Putty into Python Form Schlazen 5 8,783 Dec-13-2022, 06:28 AM
Last Post: divya130
  Python Idle won't start totalmachine 9 5,860 Oct-16-2022, 05:57 PM
Last Post: totalmachine
  How split N days between specified start & end days SriRajesh 2 2,191 May-06-2022, 02:12 PM
Last Post: SriRajesh
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 2,212 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  Assigning a new value to variable uriel 1 2,176 Dec-04-2021, 02:59 PM
Last Post: Underscore

Forum Jump:

User Panel Messages

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