Null object in Python

If you are asking whether there is a null object is Python, the answer is: no, there isn’t. But it doesn’t mean you can’t assign a variable with no value.

The equivalent of null in Python is None. It does the same thing as null.

The case is very important here. You can’t write: none, NONE, nONE, etc., you have to write exactly None.

Here’s how it looks like inside Python:

a = None

if a:
    print('There is a value assigned to the variable')
    print('There is nothing assigned to the variable')

This code will return this output:

There is nothing assigned to the variable

The “if a” means the same as “if a is not None”. It’s just a quicker way to do it in Python.

You could also use “if a != None” but this code is not an elegant way, and you shouldn’t use comparison operators with None.