Select objects by coordinates

I want to control the selection of objects by coordinates. can I select all objects at Z=5? Also, please tell me how to do this.

for object in bpy.data.objects: 
    If object.location[2] == 5: 
        object.select = True