
Python is an object-orientated, interpreted, programming language, that is generally considered “easy to use.” You can run Python on many operating systems including Windows, Mac OS X, and Linux.
Its is not named after the snake, but named after Monty Python, which the creator of Python, Guido Van Rossum, was obviously a huge fan. If you read through the Python documentation, you will find many references to Monty Python sketches littered throughout. Python was first released February 20th 1991.
In this video we will learn about variables. Variables are your first friends when it comes to Python Programming (well, programming in general). A variable is a way to give a meaningful name to a stored valued in memory.
If you picture and area of memory as a box and we place a meaningful label on that box such as population. We then take a value, such as 5000000, and place it inside the box labeled population. Now, when we want to retrieve our population value, we know where it is stored. Python will work with your computer to store a value in an area of memory and the variable name you use is the label required to retrieve the information from memory.
In this lesson we will learn about Reserved Keywords in Python. Reserved Keywords cannot be used as variable names, function names, or any other identifiers in Python. Watch the video and check out your Reference Workbook for more information.
In this lesson we will witness the power of the print() function. The print() function is a built-in Python function that enables you to print information to the interpreter window / console in your IDE. We will learn more about built-in functions in the Built-in Functions section, but the print() statement is far too important to wait until then to unveil.
In this lesson we will take a look at commenting in a Python script. Comments are ignored by the Python Interpreter. Comments help to make your code more readable, provide explanations, and document the purpose of different sections of the script.
In this video we will look at line continuation in Python. It is important to keep code neat and readable. When lines of code are too long you can split the code across multiple lines. Line continuation is therefore a valuable tool for writing clean and maintainable code.
In this video we will look at two methods for applying line continuation:
Implicit using () and [] – you can also use {}
Explicit using a \ (backslash)
In this lesson we will look at indentation which is a critical aspect of the syntax and defines the structure of code blocks. Python uses indentation to indicate the grouping of statements withing loops, conditional statements, and other program flow structures. We will progressively see indentation throughout this course. While it is an important element of the Python syntax, it is also useful for making data structures, such as dictionaries, easier to read.
We know from the Reserved Keywords lesson that None is a part of their gang. As such, you cannot use None as a variable name. If I asked you, “what is a NULL value?”, would you be able to give me a concise answer?
In this lesson we will see how we can ask Python for help via the interpreter window.
In this lesson we will take a look at integers with Python. An integer (int) is used to represent a whole number. Whole numbers do not have a decimal point and can be positive or negative.
In this lesson we will be introduced to the float object type in Python.
A float (floating point number) is used to represent decimals / fractions in Python. A float has a decimal point with one or more numbers to the right of the decimal point. A float can be positive or negative.
While not exactly a numerical data type, bool is used to represent binary (0/1) and thus, True or False.
We have seen a string a few times so far. We saw a string literal when we printed Hello, Geospatial World! and we assigned a string object to a variable with country = “Ireland”. This is your official introduction to strings.
In this lesson we will take a look at indexing and slicing as they relate to a string. Indexing in Python is zero based, meaning that 0 (zero) is the first element, for a string the first element is the first character.
In this lesson brief lesson we will take a look at string immutability. The important take is that once a string has been instantiated it cannot be altered. You need to overwrite a string variable in order to replace a string.
In this lesson we will see the magic of string methods. We’re really getting into the good stuff now. String methods in Python are built-in functions that are specific to strings and allow you to perform various operations on string objects. These methods provide convenient ways to manipulate strings.
String formatting in Python is the process of creating strings with dynamic content by substituting placeholders with values, allowing for the representation of variables, expressions, or formatted text within a string template.
In this video we will briefly see the old style from Python 2, followed by using the string format() method, and finish up with formatted string literals.
It is important to be consistent with your formatting approach. I would recommend the latter of those showcased and focus on using formatting string literals.
In this lesson we will witness the wonders of escape characters. Escape characters allow you to represent characters that cannot be easily typed or require special handling within a string.
In this lesson we will revisit string concatenation that we briefly saw back in the print() video. String concatenation is the process of combining or joining two or more strings to create a new string. The whole String Formatting section was basically string concatenation, but legacy concatenation uses the + symbol and you will see it littered all over the internet. While it is good know, it is reccommened to avoid using unless necessary. Use the string formatting methods instead.
In this video we will also look at using the string object join() method to concatenate strings from an iterable.
In this lesson we will revisit string concatenation that we briefly saw back in the print() video. String concatenation is the process of combining or joining two or more strings to create a new string. The whole String Formatting section was basically string concatenation, but legacy concatenation uses the + symbol and you will see it littered all over the internet. While it is good know, it is reccommened to avoid using unless necessary. Use the string formatting methods instead.
In this video we will also look at using the string object join() method to concatenate strings from an iterable.
In this lesson we will get an overview of the list data type in Python.
In this lesson we will take a look at indexing and slicing as they relate to a list. Indexing in Python is zero based, meaning that 0 (zero) is the first element, for a list the first element is the first object in the list.
In this lesson we will take a look at list mutability. The important take away is that you are able to alter a list in place. Unlike strings, lists are mutable. Any action performed on the list affects the elements of that list without the need to overwrite the variable.
In this brief lesson we will take a look at nested lists. A list can contain lists. A list can contain lists and each list can contain more lists. It can get confusing. Make sure to try out the challenge at the bottom after the Python Snippets section.
We have already seen how to get the length of a list using the built-in len() function. We will take another look here to drive home the fact that the maximum positional index for a list is the length of the list minus one. In this video we will also look at list membership, is an object present in the list or not?
In this lesson we will take a look at unpacking a list. Unpacking a list in Python refers to the process of extracting elements from a list and assigning them to individual variables.
List methods in Python are built-in functions that are specific to lists and allow you to perform various operations on list objects. These methods provide convenient ways to manipulate and extract information from a list. Remember, lists are mutable, when you call a list method you are altering the variable in-place.
In this lesson we will get an overview of the tuple data type in Python. Tuple are similar to lists but with some defining differences. The content throughout this section is similar to that we saw in the Lists sections, but it is important to know the overall differences between the two data types.
In this lesson we will take a look at indexing and slicing as they relate to a tuple. Indexing in Python is zero based, meaning that 0 (zero) is the first element, for a tuple the first element is the first object in the tuple.
In general, a tuple is immutable. This means that the tuple cannot be altered in place. We will explore this within the lesson and highlight that you can access and update mutable objects, such as a list, within a tuple.
Immutability ensures that data stored in tuples remains constant, providing stability and predictability in programs. It guarantees that the tuple’s integrity is maintained, preventing accidental modifications. Immutable objects like tuples are more memory-efficient than mutable objects because they do not require additional overhead for dynamic resizing or memory management.
Tuples are hashable, meaning they can be used as keys in dictionaries or as elements in sets, providing fast lookup and retrieval.
In this brief lesson we will take a look at nested tuples. A tuple can contain tuples. A tuple can contain tuples and each tuple can contain more tuples. It can get confusing. Best to keep nesting limited and only where required.
We have already seen how to get the length of a tuple using the built-in len() function. We will take another look here to drive home the fact that the maximum positional index for a tuple is the length of the tuple minus one. In this video we will also look at list membership, is an object present in the tuple or not?
In this lesson we will take a look at unpacking a tuple. Unpacking a tuple in Python refers to the process of extracting elements from a tuple and assigning them to individual variables.
Tuple methods in Python are built-in functions that are specific to tuples. There are only two methods available for a tuple; count and index. We will take a look at both in this video.
In this lesson we will get an overview of the dictionary data type in Python.
In this lesson we will see how we can access the values within a dictionary.
In this lesson we will take a look at how we can modify existing values in a dictionary and also how we can add new key: value pairs.
In this lesson we will remove/delete entries or key:value pairs from a dictionary.
In this lesson we will take a look at more dictionary methods. Dictionary methods in Python are built-in functions that are specific to dictionaries and allow you to perform various operations on dictionary objects. These methods provide convenient ways to manipulate and extract information from a dictionary.
In this video we will look at dictionary membership, is an object present in the dictionary as a key or a value?
In this lesson we will take a look at nested dictionaries. A nested dictionary is a dictionary within a dictionary. The nested dictionary is the value for a key in the dictionary. You can have dictionaries, within a dictionary, within a dictionary and so on.
In this lesson we will see the difference between using immutable dictionary keys versus mutable.
In this lesson we will get an overview of the set data type in Python.
In this lesson we will create a set from three different iterables, a string, tuple, and list. The built-in set() function must take an iterable to create a set.
In this lesson we dive into the heart of set theory with set operations. We will take a look at four operations; union, intersection, difference, and symmetrical difference. Make sure to fill in your reference workbook!
In this lesson we will assess set membership with the “in” and “not in” keywords. Just like lists, tuples, and dictionaries, set membership always returns a Boolean value of True or False.
In this lesson we will take a look at some set methods. Set methods in Python are built-in functions that are specific to sets and allow you to perform various operations on set objects. These methods provide convenient ways to manipulate a set, extract information from a set, and perform operations on a set. Make sure to fill in your reference workbook!
In this lesson we will take a look at a frozenset. Python provides an immutable variant of sets called “frozensets” which are created using the in-built frozenset() function. Frozen sets are hashable (immutable) meaning they can be used as dictionary keys or elements of other sets
In this lesson we will assess numerical operators, which allow us to perform mathematical calculations. Check out your reference workbook and fill in a description of each operator in the table provided.
In this lesson we will take a look at numerical operator precedence which follows the PEMDAS order.
P-arenthesis
E-xponentiation
M-ultiplication
D-ivision
A-ddition
S-ubtraction
In this lesson we will assess comparison operators. Comparison operators in Python are used to compare two values and determine the relationship between them. They return a Boolean value (True or False) based on the comparison result. Check out your reference workbook and provide a description in the table for each operator.
In this lesson we will assess logical operators which are used to combine multiple conditions together and evaluate them as a single Boolean expression. Check out your workbook and fill in a description for each logical operator in the table, and also try the “Try it yourself” section below the Python Snippets.
In this lesson we will assess short-circuiting with logical operators. Short-circuiting refers to the behaviour where the evaluation of an expression involving logical operators stops as soon as the outcome is determined, without evaluating the remaining operands.
The ‘if’ keyword in Python is a fundamental part of conditional statements, allowing the execution of specific blocks of code based on whether a condition is true or false.
The elif keyword in Python is used in conjunction with the if statement to evaluate additional conditions after the initial if condition is found to be false.
The else keyword in Python is used in conjunction with the if statement to define a block of code that should be executed when the condition of the if statement evaluates to false, or when the conditions of the if and one or more elif statements evaluate to False.
The for loop in Python is used to iterate over a sequence (such as a list, tuple, string, or range) or any iterable object, executing a block of code for each item in the sequence.
The while loop in Python is used to repeatedly execute a block of code as long as a specified condition is true. Here’s all you need to know about the while loop.
In this lesson we will take a loot at controlling flow in action with a defined workflow. We have a dictionary where the key represents the Object ID of a feature and the value is a dictionary representing the attributes of each feature. The attributes contain the name of a country, the population and the area in square kilometers.
We wan to create a dictionary that has processed the data to calculate the population density for each country. The processed data will sit in a dictionary where the key is the name of the country and the value is the population density.
Finally, we want to create a list that contains list, where each list has two values, the name of the country and the population density value. The catch is, that we want the list of lists to be ordered by lowest population density.
This is An Introduction to Python Programming with a GIS Focus. This course is designed to instill the basics of Python Programming by incrementally increasing your knowledge section-upon-section. The course comes with a Reference Workbook for you to add information to at each section. This will enhance the learning experience and make the material stick. The Reference Workbook is something your future-self will appreciate as you refer back to it on you Python journey for information and code snippet examples.
So how does this course have a GIS focus? Simple, most elements of the course have GIS and geospatial data in mind. Instead of using non-descript variables and values, we will use terms such as population, city, x_coord, y_coord, and so on. This will aid participants with pinpointing how they can relate geospatial data to Python. There are some elements, for simplicity, we will use an alternate approach. At the end of most sections we will have a ‘GIS Use Cases’ topic which will further demonstrate where the material from the section can be applied in GIS.
What you will learn...
An overview of what Python Programming is
What variables are
Python data types (numerical, string (text), list, tuple, dictionary, set)
Operators (numerical, logical, comparison)
Efficient comprehension with Python
Controlling program flow
Built-in functions
Exceptions handling
Object Orientated Programming (OOP)
The Standard Python Library
All you need for this course is a computer and motivation to learn. You simply cannot learn Python in two hours no matter what other courses might tell you. The key is to be a consistent learner. The content of this course covers a lot, but there is still work for you to do and that is where the Reference Workbook comes in to play. By following this course and filling in the workbook you will supercharge your Python learning an application of the programming language from the start.
You course instructor, Glen Bambrick, has over 18 years as a GIS Professional with over 10 of those years utilising Python for geospatial tasks and automation mainly with the Esri ArcGIS software suite. Glen is also an Esri Communities MVP mainly answering questions and providing solution for the ArcGIS API for Python and ArcPy.
Thank you for your interest in this course.