# Phyton statement if/else - string/double

3759
9
12-13-2015 12:31 AM
New Contributor III

Hi,

I stuck with simple expression in field calculator in ArcGis. I hope you`ll help me. The picture below contain two fields "Zal" (Double) and "W_zal" (string). I would like to fill field "W_zal" based on "Zal". For example: if Zal > 10, W_zal is 'text', if Zal < 10 , W_zal is "text_2". I`dont know whats is wrong, brackets, spacing... I`ll be grateful for yours help.

Tags (4)
1 Solution

Accepted Solutions
New Contributor III

Thank you Dan!

9 Replies
MVP Legendary Contributor

select the python parser

and use this as the expression in the code block.  I have written the example verbosely so you can follow the logic.  It is always best to assign the required output and return the final value after the fact to ensure that all is correct.

```def convert(val,fld):
if fld > 10:
val = "text"
else:
val = "text2"
return val```

and this in the expression box

`convert(2, !Zval!)`

here is an example using a slightly different example... but the principle is the same.

New Contributor III

Thank you Dan!

MVP Esteemed Contributor

Perhaps you could mark this as Answered since the information Dan provides is spot on.

That should just about do it....
MVP Legendary Contributor

Joe... I think Bartosz is long gone... it get randomly bumped up the pile over time though

MVP Legendary Contributor

Ahhh good... at least the thread is closed

MVP Frequent Contributor

But awarding the answer to yourself is a bit....

MVP Legendary Contributor

I didn't... Bartosz thought his thank you was the correct answer... perhaps the final closure is solution enough

New Contributor III

Hi guys,

Sorry for that mistake.

MVP Legendary Contributor

Its ok... the question has been getting bumped up randomly over time.  At least it is closed now.