From the course: Learning ArcGIS Python Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

String manipulation

String manipulation

- [Instructor] Python scripts have to handle a lot of different types of text: geo-database names, file paths, strings read in from attribute tables. All of these things are held in string variables, we need to make sure we know how to use these strings properly to save us a lot of frustration when debugging a script. As we've already learned, strings can be surrounded in single or double quotes, but each pair has to match. So, here, I'm printing out the names of two different shape files. In one case, I use single quotes, the other I use double quotes, that's no problem, works just fine. Anything inside the quotes gets treated as literal text, exactly as it's typed. Well, almost everything. There are a few special escape characters that have special meaning inside the quotes, and they're prefaced with a backslash. This time, I'm printing three elements, the string Roads.shp, and then a funny little thing called \n, and then Rivers.shp. But watch what happens when I run it. You see…

Contents