Python Made Easy (2013)

Chapter 2: Getting Started

"Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language." - Peter Norvig, director of search at Google.

In this chapter you will learn:

 

·  What is the Integrated Development Environment

·  How to make a sample program?

Its time to get to know Python! There will be a few resources that you need to know about before we dive head-first into the code. We'll start by installing the best IDE for Python use, PyCharm.

Integrated Development Environment

If you already know about IDEs, feel free to skip on this section. If you do not, I’d advise you to read it first.

Regardless of what programming language you go for, you will need an IDE (an abbreviation for Integrated Development Environment). An IDE provides programmers with the tools she or he needs:

·     The Source Code Editor- this is a text editor program that can be used to edit the source codes of various programs on your computer.

·     Build automation tools- these tools are used for build automation. Build automation is something that programmers do quite frequently. These tools enable you to compile sources codes in the form of binary codes, running automated tests and such like.

·     Debugger- you will always come across some bug or the other. The debugger helps you detect and then, get rid of these bugs so that the computer program is free of bugs and errors.

Installing Python and an IDE

Python is relatively easy to install, and doesn't require a whole lot of knowledge. Navigate to the download page located here:

https://www.python.org/download/releases/2.7.8/

This is the most commonly used version of Python. Make sure that you download the correct file, based on your operating system. Some operating systems might not be capable of supporting a particular version of the programming language.

Open the installation file and click “Install for all users.”

Installing an IDE

For an IDE, we will be using PyCharm. You can access their download page here:

http://www.jetbrains.com/pycharm/download/

PyCharm is one of the most popular IDE's for Python. It's simple, easy to use, and comes with a built in command prompt, which truly simplifies things for beginners. The best feature is that the community edition is available completely for free, offering all of the standard features for Python development. Make sure to select your operating system from the tabs at the top of the page before downloading. Your download will be more than 100 MB, so it could take some time to complete. The installation process is relatively straight forward.

Example Program

You'll be shocked by how little code is actually required when programming in Python. Compared to other languages, you might see half (or less) of the total number of lines of code. But don't mistake that for a lack of depth. Python is robust, with enough features for companies like Google and Facebook to choose Python as a primary language for some of their largest business processes.

Remember that Python in its simplest form is nothing more than a text file with Python statements. If you are coming to Python from C# and other similar languages, executing files is a bit different in Python, and often a less visual process.

Here I will walk you through the creation of a sample program. It will be your typical “Hello, World” opener that you've likely seen before.

Step 1: Open PyCharm.

Step 2: Go to File > New Project

Step 3: In the “Project name:” section, enter “HelloPythonWorld”, then click OK. Make sure you have the correct interpreter selected. Your screen should look like this:

Step 4: In the project window, right click on the folder named “HelloPython World” and select New > Python File.  When prompted, name the file “HelloP”.

Step 5: Copy and paste the following code into the text editor:

print "Hello, World!"

Step 6: In the “Run” Menu, click “Run”.

Step 7: You will be prompted to specify what you would like to run. Select “HelloP”.

Step 8: Look at the logs that were generated after running the program. It doesn't look like much. You should be seeing something like this;

While this not seem like anything significant, the logs have signalled that the program ran correctly. This is excellent! However, many users will prefer to see a visual representation of their program. Here's a simple way to do so;

Step 9: Click your start button. Use the search function (or manually navigate) to the “Python (command line)” program.

Step 10: Once the command prompt opens, type the same line of code from step 5 into the command prompt. You should see the following:

As you can see, the command was executed within the command prompt.

This gives you a good overview of how to go about creating a project and watching it run. Unlike other programming languages, Python doesn't need or utilize a graphical user interface when running a program. This can be confusing for those that are coming over from other visual programming languages, but ultimately doesn't effect much.

Summary

ü       Here are the points that were covered in this chapter:

·     What is an IDE

·     What does an IDE consist of

·     How to make a sample program with Python

·     The basics of programming with Python