[GIS] Using Python to Calculate a field

arcgis-10.1field-calculator

I am trying to replace values in a single column using an else if statement, but I keep getting an Syntax error in line 2. I'm new to Python so it's probably an easy solution, but I haven't been able to figure it out. I am using ArcMap 10.1.

    def Replace(SrcLevel):
      if SrcLevel == 0:
        return "4-Other"
      elif SrcLevel == 1:
        retun "1-Primary"
      elif SrcLevel == 2:
        return "2-Middle"

    SrcLevel = Replace(!SrcLevel!)

Best Answer

At least four things needed correction:

  1. You need to use return rather than print
  2. You need to use == rather than = on your if and elif statements (thanks @DanPatterson)
  3. Take care with your indentation - your print (to become return) statements don't seem to line up
  4. return statement was written in one place as retun [sic]

There are examples here.