How to find if object exit or not?

i can find object like this
but how do i test if it exist or not ?

name1 = “matercube”

bpy.data.objects[name1

if it does not exist it gives an error
but how to test and get a true or false for exitance of the object ?

if it does not exist then i have to create a new one
but no material - mat will be added elsewhere

thanks
happy bl

if name in bpy.data.objects :
    #Object exists

basically any collection in blender have get() method and using item name to get item data

image

for example :

obj_cube = bpy.data.objects.get('Cube')
if obj is not None:
    print('cube exist')

will that get thing find object in all collections or only the enable one ?

thanks
happy bl

collection status (enable or exclude) in outliner does not effect to the object

image