Field Calculator Python Joining Concatenation - anthonyblackham/GIS-Wiki GitHub Wiki

Sometimes you'll want to join multiple fields together but it is important to be aware of the stipulations.

If you are using python to join fields the syntax is !Field1! + !Field2!: very simple, BUT the + is also used in basic arithmetic operations, so lets say Field1 was a 5 and Field2 was a 2 do you want it to return 52 or 7? Because Python can't read your mind you need to tell it exactly what you want it to do.

You can add fields together as long as the data types are all the same (eg adding two text fields hot and dog will yield hotdog) If you want to add a integer field with a text field Python won't be too happy with you based on the syntax mentioned above so you have a couple options.

Option 1:

You can create a new field with the text data type and put in your numbers and they will join happily with your text values

`!Field1! + !Field2!`

Option 2:

You can cast your non-string field as a string as part of the join so you won't need to create a new field

"".join([str(i) for i in [!field1!, !field2!, !field3!] if i])

Whatever is set inside the first quotation marks is defined as your delimiter, so if you want each field to be separated by spaces, add a space.