🐍 Python - Data Types
Data Types
Updated at 2017-01-03 01:22
Python does not have null, but None. None is a singleton object without behavior.
database_connection = None
try:
database = MyDatabase(db_host, db_user, db_password, db_database)
database_connection = database.connect()
except DatabaseException:
pass
Never check for None with == syntax, use is. Classes may overwrite __eq__ operator with an implementation that does not take into account other being None.
if database_connection is None:
print('The database could not connect')
else:
print('The database could connect')