How would I add multiple python expressions in the ArcMap Field Calculator if possible?

I tried separating each expression on a new line and also separating with a semi-colon but neither worked.

Here are the expressions I am trying to execute at once:


'_'.join(num.zfill(4) for num in !field!.split('_'))

  • You want to to do all these process on the same output field ? In this case you should do python function in the code bloc
    – S_TssG
    Commented Apr 9, 2015 at 16:21
  • Yes these are all on the same output field. Do you have an example of how to turn these into a function?
    – Mat S
    Commented Apr 9, 2015 at 16:24

2 Answers 2


Am I correct in assuming you wish to carry out the operations in sequence i.e. the final value in the field comes from the !field![:9] operation?

If so, i would have the code block as:

def field_calc(field):
    str1 = field.replace("+","")
    str2 = "_".join([num.zfill(4) for num in str1.split('_')])
    str3 = str2[:9]
    return str3

Then call it using:


This will carry out each process in sequence, carrying the result forward. I haven't tested this since I don't have the data but I think it should do the trick.


In the code bloc :

def calcField(field):
 f1 = field.replace("+","")
 f2 = '_'.join(num.zfill(4) for num in field.split('_'))
 f3 = field[:9]
 return f1+f2+f3

in the expression line: calcField(!field!)

  • It looks like it ran 3 separate times since the text is repeated 3 times. And it looks like only the second time ran correctly.
    – Mat S
    Commented Apr 9, 2015 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.