ArcPy and ArcGIS(Second Edition)
上QQ阅读APP看书,第一时间看更新

For loops

Built into all programming languages is the ability to iterate over a dataset to perform an operation on the data, thus transforming the data or extracting data that meets specific criteria. The dataset must be iterable to be used in a for loop. We will use iteration in the form of for loops throughout this book. Here is a simple example of a for loop, which takes string values and prints them in uppercase using the string upper method. Open IDLE (Python GUI) from the Start Menu/ArcGIS/Python2.7 folder to try a for loop. Enter commands at the Python interpreter's triple chevron >>> :  

>>> newlist = ['a','b','c','d']
>>>for value in newlist:
print value.upper()
A
B
C
D