From the course: Learning ArcGIS Python Scripting (2018)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Conditional statements - ArcGIS Tutorial
From the course: Learning ArcGIS Python Scripting (2018)
Conditional statements
- [Instructor] Sometimes you need your Python script to stop and make a decision before moving on. For example, suppose you write a Python script that's gonna run the erase geoprocessing tool, which requires at least a standard ArcMap license. How do you check to see if the user has at least a standard license? You use a conditional statement, an if statement. If statements let you control the flow of your script. For example, suppose your script asks the user for a road name, and then it checks to see if a road name was entered. Did you get a value from them? Yes? Okay, try and select the road. No? Ask them to enter it again. The syntax for an if statement looks like this if some condition is true do something. There's a colon at the end of the first line. So if some condition is true do something, else, do something else. To make comparisons in an if statement, you'll need some comparison operators. To compare if two values are equal you use a double equal sign. A single equal sign…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.