6.6. Using the Special Object None

None is a special object in Python used to signify the absence of a value. It pops up all over the place in Python. It is the value automatically returned by a function or method unless you specify otherwise. The existence of None gets nicely around an ambiguity found in languages with no such concept. This is best illustrated by example.

In the following code snippet, the empty string and the number 0 are used to mean “Surname does not exist” and “No such account holder,” respectively.

CD-ROM reference=6026.txt
x = getSurname("Sean")
if x == "":
        print "Surname does not exist"
        balance = getBalance("Sean")
        if balance == 0:
                 print "No such account holder"

In the getSurname case, the use of an empty string to ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.