Select objects with prefixes using Python

Hi everyboady,

I’m trying to select objects with many prefixes, but it dosen’t work if I change the prefixes order. I tried with this code :

for obj in bpy.context.scene.objects:
    if obj.name.startswith('BGR_' and 'M_' and 'L_'):
        obj.select_set(True)

Any idea ?
Have a nice coding day !

I change the code like this and it works :

bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.context.scene.objects:
    if obj.name.startswith(('BGR_','M_','L_')):
        obj.select_set(True)

It doesn’t work without double parenthesis.

the ‘double parenthesis’ you mentioned is a tuple. without parens around the tuple, they are just parameters.

1 Like