Analog of len for tensors?

I’m trying to write a code that will easily support both 2D and 3D problems. If I have a vector valued function u, I can just call len(u) to determine which case I am in. But is there any analog for tensorial fields?

Is u a ufl variable of some kind? u.ufl_shape may be what you’re looking for.