NGA Advanced Python Programming for GIS, GLGI 3001-1

Python data types

PrintPrint

Python contains many data types built in. These include text, numeric, sequence, mapping, sets, Boolean, binary and None. Coding at its core is largely working with data that is in one of these types and it is important to know them and how they work.  

As a developer, you need to know types for operations and for parameters and this helps with debugging, performing conditionals, calculations, dictionary operations, and data transformations. For example, the string “1” does not equal the int 1. Trying to add “2” + 5 will result in a TypeError 

res = "2" + 5
print (res) 
Output 
Traceback (most recent call last): TypeError: can only concatenate str (not "int") to str

Changing the 5 to “5” results in concatenation of the “2” and “5”:

res = "2" + "5"
print (res) 
Output 
25

For this course, we will be looking at more advanced structures in the mapping type. W3 provides a great overview of the data types and I encourage you to review them.