Your code is not correctly formatted Python code:
- Indentation is important in Python, as it defines where functions and conditions start and end.
- You need a
:
after the function definition
- The correct operator for equality-comparison is the
==
and not simply =
which assigns a value to a variable.
Also, with respect to the field calculator in ArcGIS, if you use a function to calculate your value, you also will need to check the "Show Codeblock" check box.
In your case, you have two possibilities:
Your if/else-statement is very simple, so you could rewrite in a single Python line, and there is no need for a codeblock:
"SampleText" if !Coded! == 1 else "SampleText_2"
Using a code block, with the code block checkbox activated, the code block should be:
def Text_d(Coded):
if Coded == 1:
return "SampleText"
else:
return "SampleText_2"
and then in the "Coded=" box below you would need to write:
Text_d(!Coded!)
This second method gives you the possibility to use many Python functionalities such as nested conditions:
def Text_d(Coded):
if Coded == 1:
return "SampleText"
elif Coded == 2:
return "SampleText_2"
else:
return "SampleText_3"