I Spy Code - Python

Test For Null Object

In Python, the null object is the singleton None.

Here is a python example that shows how to test if a reference is None (null):

Source: (example.py)

def getNone():
  return None
 
foo = getNone()
if foo is None:
  print("foo is none")
 

Output:

$ python example.py
foo is none


Related Examples

Call Methods Dynamically
Docstring
Initializing Object Variables
Method Arguments
Subclass Inherits Method
Test For Null Object
hqdwppls.php

7