GEOG 485:
GIS Programming and Software Development

Lesson 1 Practice Exercise 1 Solution

PrintPrint

Solution:

x = "Hello"
print (x)

Explanation:

The first line of the script tells the Python code interpreter to set aside space in the computer's memory to hold a value, to refer to that space in memory by the name x and to store the text string "Hello" in that space. The memory space is typically referred to as a variable. Unlike some languages that require declaring a variable and defining the type of data it will hold before assigning a value to it, Python allows variables to be defined without explicitly specifying their type. The data type (string, number, etc.) is inferred by the Python code interpreter based on the kind of value you're assigning to the variable.

The second line of the script tells the interpreter to print the contents of the x variable to the PythonWin Interactive Window.

Note that this already simple script could be simplified even further by doing away with the x variable and plugging "Hello" into the print statement directly as literal text:

print ("Hello")

Note also that this script does not include lines that import arcpy since the script does not require any ArcGIS functionality.