Select object by dimension I'm trying to select objects that meets certain criteria in this case their dimension (not the scale) but I'm unable to figure out the proper way to make it work.
I have a over simplistic script which doesn't work although the context is the right one in the python console.
import bpy

for obj in bpy.context.scene.objects:
    if bpy.context.object.dimensions[2] = 2.0:
        obj.select_set(True)

Here is the final working code following the suggestions:
import bpy
from math import isclose


scene = bpy.context.scene

for obj in scene.objects:
    x = obj.dimensions[0]    
    y = obj.dimensions[1]
    z = obj.dimensions[2]
            
    if obj.type == 'MESH':
        if (isclose(y, 2.1, rel_tol=1e-3)):
            obj.select_set(True)
            bpy.context.view_layer.objects.active = obj
        else: 
            obj.select_set(False)
Allow for precision errors.
In addition to @Secrop's answer, it is a good idea to allow for precision errors when testing equality of floats, ie 2.000001 is probably close enough to 2.
A commonly seen test to see if a value is within a tolerance TOL of 2
if abs(value - 2) &lt; TOL

or in the case here, using math.isclose
import bpy
from math import isclose

context = bpy.context

scene = context.scene

for ob in scene.objects:
    ob.select_set(
            isclose(ob.dimensions.z, 2, rel_tol=1e-6)
    )

which is  setting the selection of all objects in the scene to the test result.
Using
if some_test_is_true:
    ob.select_set(True)

will make no change to selection if all where selected beforehand.
Can extend a selection using or.
    ob.select_set(
            ob.select_get()
            or
            isclose(ob.dimensions.z, 2, rel_tol=1e-6)
            )

or, as shown in your answer, add other specs with and eg ob.type == 'MESH' and ...