
上QQ阅读APP看书,第一时间看更新
Functions
Functions are used to take code that is repeated over and over within a script, or across scripts, and make formal tools out of them. Using the keyword def, short for "define function", functions are created with defined inputs and outputs (which are returned from the function using the keyword return). The idea of a function in computing is that it takes in data in one state, and converts it into data in another state, without affecting any other part of the script. This can be very valuable for automating a GIS analysis.
Here is an example of a function that returns the square of any number supplied:
def square(inVal):
return inVal ** 2
>>> square(3)
9