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
  ''.join and start:stop:step notation for lists ringgeest11 2 2,448 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Error: can't start new thread maha2 0 1,461 Jun-13-2023, 12:26 PM
Last Post: maha2
  Start print a text after open an async task via button Nietzsche 0 717 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Start Putty into Python Form Schlazen 5 5,505 Dec-13-2022, 06:28 AM
Last Post: divya130
  Python Idle won't start totalmachine 9 3,543 Oct-16-2022, 05:57 PM
Last Post: totalmachine
  How split N days between specified start & end days SriRajesh 2 1,338 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 1,533 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  Assigning a new value to variable uriel 1 1,614 Dec-04-2021, 02:59 PM
Last Post: Underscore
  Start loop from different points TheHolyPyGrenade 3 2,086 Apr-11-2021, 07:57 PM
Last Post: TheHolyPyGrenade
  How to start the program from the beginning. iamaghost 5 2,957 Feb-23-2021, 03:40 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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