How to put if condition for empty material index
You can find more info on if statements in Python here.

You can find a lot of useful information about bpy in Blender's Python console using the auto complete function (Ctrl+Space):



The script you are after could be something like this:

import bpy

obj = bpy.context.object
name = "My_node_name"
if obj is not None:
    if obj.type == 'MESH':
        if obj.active_material is not None:
            if obj.active_material.use_nodes:
                nodes = obj.active_material.node_tree.nodes
                if nodes.get(name) is not None:
                    print(name + " node is in the material's node tree.")
                else:
                    print(name + " node is not in the material's node tree.")
            else:
                print("Material does not ue nodes.")
        else:
            print("Object does not have an active material.")    
    else:
        print("Object is not a mesh.")
else:
    print("There is no active object currently in the scene.")