In this video, Jennifer Harrison introduces three basic looping constructs used in Python. Learn the basic syntax for writing loops and how to make a block of code repeat, such as doing something for each feature class in a geodatabase.
- [Instructor] When you have a list of data…that you wanna run some code on,…you use a looping construct.…A loop lets you execute a set of code…over and over again.…For example, you can do something…to all the feature classes in a geodatabase,…all of the layers in a map,…or all of the text files in a folder.…Loop blocks start with a specific line of code,…the word, for, or while, or for each,…and the first line has to end with a colon.…The next line,…and all of the lines…that are part of the loop block…must be indented,…to exactly the same number of characters.…
It's the indention that determines…what is a part of the loop.…You end the loop by moving the next line of code…back to the margin with no indention.…By the way, you can have loops inside of loops,…and it's very common in scripting.…The indention for each loop…can be any number of spaces,…but all the lines in a single loop…have to be indented by…exactly the same number of spaces.…There are several kinds of loops…that are built into the core module of Python.…
- Writing and running Python scripts in IDLE
- Making scripts flexible with variables
- Commenting scripts
- Manipulating string data
- Object-oriented programming in Python
- Creating loops
- Reading and writing text files
- Capturing input at runtime
- Documenting your scripts
Skill Level Beginner
1. Python for ArcGIS Basics
2. Strings, Numbers, and Variables
Work with numeric values5m 22s
3. Syntax Rules
4. Manipulating Strings
5. Object-Oriented Programming
6. Using Loops
7. Generate Log Files
8. Input at Run Time
9. Help Documents
Documenting a script1m 59s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.