Any respectable programming tutorial starts with a hello world example, so let’s get that out of the way!

If you haven’t opened the Python console yet, do it now: Plugins | Python console.

The Python console is an interactive command line interface. This means that you can type in a line of code and – once you press Enter – the code is executed.

In our hello world example, we use the print function to output the text “Hello world!” in the console. The corresponding code is:

print("Hello world!")

We are calling the print function with one parameter: the text (also known as string) value “Hello world!”.

When you type this command into the Python console input field, you’ll see that it shows text in different colors. This is called syntax highlighting, and the colors make it easier to make sure that what we’re typing is correct. In addition, when typing closing brackets, it highlights the corresponding opening bracket. This is very useful, since missing brackets are a common programming mistake.

If you have seen some Python code in the past, you might have seen print statements such as print “Hello world!” without brackets. This syntax is not valid in Python 3 anymore and would cause this error: SyntaxError: Missing parentheses in call to ‘print’

After pressing Enter, you will see that our code outputs Hello world! in the console:

These are the basics of using the Python console and how to execute a function with a string parameter.

That’s enough non-GISy basics for now, let’s get our hands dirty with some spatial data!


PyQGIS 101 is a work in progress. I’d appreciate any feedback, particularly from beginners!

  1. bruceb said:

    I am going to follow your course here, However, as a beginner python wannabe I am looking for an explanation as to why I need to use programming, what is the advantage of using programming vs using the QGIS tools. So some context as to why would be useful.

    • Hi Bruce. There are tons of articles and videos on why one should learn programming. Therefore I’m not planning to elaborate on this topic here but rather spend my time on explaining PyQGIS.

      • This is awesome am so exited

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: