SharedType_data / NoneType.ipynbOpen in CoCalc
Use type NoneType

Создание

my_none = None
print(my_none)
None
print(type(my_none)) #вывод типа переменной my_none
<class 'NoneType'>

Проверка условия:

if my_none is None:
    print('The database could not connect')
else:
    print('The database could connect')
The database could not connect

Условие так же можно проверять с помощью ==, но этого делать не нельзя!

class MyClass:
    def __eq__(self, my_object):
        # Просто вернем True

        return True

my_class = MyClass()

if my_class is None:
    print('my_class is None, using the is keyword')
else:
    print('my_class is not None, using the is keyword')

if my_class == None:
    print('my_class is None, using the == syntax')
else:
    print('my_class is not None, using the == syntax')
my_class is not None, using the is keyword my_class is None, using the == syntax