<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Field calculator if statement syntax error. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082389#M61850</link>
    <description>&lt;P&gt;I'm using ArcGIS Pro 2.7.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use a python function in the field calculator; which I've done before.&amp;nbsp; I've got a field with data type Double that we'll call Double_Field that I want to use to determine which value to assign to another field.&amp;nbsp; Here's what I'm trying:&lt;/P&gt;&lt;P&gt;NewValue(!Double_Field!)&lt;/P&gt;&lt;P&gt;def NewValue(num):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if num = 0:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 0 and num &amp;lt;= 3:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 3 and num &amp;lt;= 6:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 3&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 6 and num &amp;lt;= 9:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 4&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 9 and num &amp;lt;= 12:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 5&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 12:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 6&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 99&lt;/P&gt;&lt;P&gt;When I try to verify the code I get the following error&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MichaelMarlatt1_0-1627078474460.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/19291i1C0A4268E3C5879D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MichaelMarlatt1_0-1627078474460.png" alt="MichaelMarlatt1_0-1627078474460.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I've noticed that if I change the "if num = 0:" to "if num &amp;lt; 0:" or anything but a "=" comparison I no longer get a syntax error (but then code no longer does what I need it to do).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand what's going on here?&amp;nbsp; I'm a little new to Python but not to programming.&amp;nbsp; It feels a little like a type error but I cannot see how.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Michael Marlatt&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jul 2021 22:28:20 GMT</pubDate>
    <dc:creator>MichaelMarlatt1</dc:creator>
    <dc:date>2021-07-23T22:28:20Z</dc:date>
    <item>
      <title>Field calculator if statement syntax error.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082389#M61850</link>
      <description>&lt;P&gt;I'm using ArcGIS Pro 2.7.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use a python function in the field calculator; which I've done before.&amp;nbsp; I've got a field with data type Double that we'll call Double_Field that I want to use to determine which value to assign to another field.&amp;nbsp; Here's what I'm trying:&lt;/P&gt;&lt;P&gt;NewValue(!Double_Field!)&lt;/P&gt;&lt;P&gt;def NewValue(num):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if num = 0:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 0 and num &amp;lt;= 3:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 3 and num &amp;lt;= 6:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 3&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 6 and num &amp;lt;= 9:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 4&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 9 and num &amp;lt;= 12:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 5&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif num &amp;gt; 12:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 6&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 99&lt;/P&gt;&lt;P&gt;When I try to verify the code I get the following error&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MichaelMarlatt1_0-1627078474460.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/19291i1C0A4268E3C5879D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MichaelMarlatt1_0-1627078474460.png" alt="MichaelMarlatt1_0-1627078474460.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I've noticed that if I change the "if num = 0:" to "if num &amp;lt; 0:" or anything but a "=" comparison I no longer get a syntax error (but then code no longer does what I need it to do).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand what's going on here?&amp;nbsp; I'm a little new to Python but not to programming.&amp;nbsp; It feels a little like a type error but I cannot see how.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Michael Marlatt&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 22:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082389#M61850</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2021-07-23T22:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator if statement syntax error.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082396#M61851</link>
      <description>&lt;P&gt;In Python the equals comparison is written as ==, so use&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if num == 0:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 23:16:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082396#M61851</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-07-23T23:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator if statement syntax error.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082409#M61852</link>
      <description>&lt;P&gt;Another case for divmod&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def NewValue(num, divisor=3):
    """Return divmod for a field"""
    val = divmod(num, divisor)[0]
    if val &amp;gt; 6:
        return 99
    return val
    

[NewValue(i) for i in a]
[0, 1, 2, 3, 4, 5, 6, 99, 99, 99]

a
array([ 0,  3,  6,  9, 12, 15, 18, 21, 24, 27])&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 24 Jul 2021 00:54:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082409#M61852</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-24T00:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator if statement syntax error.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082744#M61860</link>
      <description>&lt;P&gt;Thank you, Tim!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 17:16:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-if-statement-syntax-error/m-p/1082744#M61860</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2021-07-26T17:16:09Z</dc:date>
    </item>
  </channel>
</rss>

