[Tutor] Use of None (was: Re: Tutor Digest, Vol 147, Issue 52)

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jun 1 18:52:28 EDT 2016


On 01/06/16 12:43, marat murad via Tutor wrote:
> Thanks for your replies,I think I understand it much better now. I Also I
> wanted to know what the 'None' does in the second program.

Please make the subject something meaningful and delete all the excess
messages. we have all seen them already and some people pay by the byte.

As for none, it just means a reference to nothing. ie no object.
So in your example:

start= None
while start != "":
    start=input("\nStart: ")
    ...

The start = None could have been replaced by anything other than
an empty string. It just creates an initial value that causes
the while loop to start.

You will often find None used like this: to create a named
value that has no significance at that point in the program
but will be used later.

Another way of writing your example would be:

while True:   # loop forever
   start = input(...)
   if start = "": break   # break exits the nearest loop
   ...



HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list