I was trying to write and if calculation and I cannot figure out the syntax to complete it. The one on the left doesn’t work as it will return the text of the calculation I am trying to perform instead of the value. One on the right is the calculation that I want to use:

No =


Code Block

def func(input):
        if '_' in input:
            return '!Form_Name!.split("_")[1]'
        elif '-'in input:
            return 'Yes'
            return 'No Match'

Calculation Formula I want to use:


enter image description here

That is what i am getting and not the caclulated value in the field.

I am new to this and trying to learn.

  • 1
    It's part of a Calculate Field expression in ArcGIS Desktop, but the code is a bit odd, and possibly incomplete, and it looks like a literal is being returned instead of an evaluated expression.
    – Vince
    Feb 16 at 13:20
  • 1
    Can you explain what you are trying to do? For example how does your input attribute table look like, and what is your expected output`?
    – BERA
    Feb 16 at 13:29
  • I think the problem are the comma around the function for the first return (comma made it a string and not a fonction)...
    – J.R
    Feb 16 at 13:51

1 Answer 1


I got it!


def func(input):
        if "_" in input:
            return input.split("_")[1]
        elif '_'in input:
            return 'Yes'
            return ''
  • The way you've written this is different to your original post. The first "elif" statement will never run because the condition is the same as the first one. Both checking for underscores. So, you'll never get "Yes" as an output. I assume in your actual code, it's written as elif '-' in input:
    – Fezter
    Mar 3 at 1:10

Your Answer

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

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