How to specify number of cuts for subdivision modifier in python I'm working on a custom panel in Blender. I can add a subdivision modifier with python like this:

subsurfMod = self.layout.operator("object.modifier_add", text ="Add subdivision", icon="MOD_SUBSURF")
subsurfMod.type='SUBSURF'


However I want to also specify the number of cuts. Something like this doesn't work:

subsurfMod.levels='3'


What do I have to use instead?
There is an operator that sets subdivision level for an object and adds the Subsurf modifier if it does not exist:

bpy.ops.object.subdivision_set(level=4)


You can call it with a button like any other operator:

self.layout.operator("object.subdivision_set", text ="Add subdivision", icon="MOD_SUBSURF").level=4