Trying to calculate using Python in 10.3 the "Region" field with text based on the first two characters in a string field called "API_10". Basically, if the left two characters in "API_10" equal "33", then populate "Region" with "North".
API_10[0:2] or API_10[:2]
Thanks Joshua!
Or the most succinct descriptor... the python docs
When you do a slice or substring in Python and it starts with "0" then the second number is always the length. This confused me for a while ..... https://www.dotnetperls.com/substring-python
Also, just pass the whole column to your function since the function does slicing and checking: Region = TextValue(!API_10!)
Joshua is correct... python slicing is 0 based and exclusive of the slice number, hence
whatever[:2] or whatever[0:2] will return 0 and 1. The slice is [start:stop:step]
whatever <SPAN class="operator token">=</SPAN> <SPAN class="string token">'abcdefg'</SPAN> whatever<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="string token">'ace'</SPAN> whatever<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="string token">'ace'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
or skipping the start and stop
whatever<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="string token">'abcdef'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.