414373 (2) [Avatar] Offline
Hi Ana,

May I know when is it appropriate to use "is None" in control statements?

Best Regards
Ana Bell (31) [Avatar] Offline
None is just a value for the special type NoneType. Compare this to something like 5 being a value for the int type. But what is special about None is that it is the only value for the NoneType type -- it has no other values! Whereas the int type has all the integers (0,1,2,3,1000,-4,-5,-6,etc).

So you can have a program that sets some variable to be None, to represent something special, like the absence of a value.

The statement is None just checks if the value of something literally is None. It is equivalent to checking if something == None. Not sure how far you are in the book, so I'll do something really simple. For example, say that you get a pet:

name_it = input("Do you want to name your dog? ")
if name_it == "yes":
    dog_name = "Ruff"
    dog_name = None

# you can check equivalence using the keyword is
# the line below is equivalent to dog_name == None
if dog_name is None:
    print("Give your dog a name!")
    print("Hello", dog_name)

414373 (2) [Avatar] Offline
Thanks, its crystal clear now, and you gave a great example smilie None == Absence of anything.