Skip to main content

Python Intro

Why Python

There are many languages to choose from, so why this one?  To answer that question you should first consider what type of development you plan to use it for and consider its benefits and drawbacks.  Python is an interpreted language which means it must be "translated" during run time.  This "translator" is technically called an interpreter and must be installed on the host system you plan to compose your script and the machine it will eventually run on.  This is both a blessing and a curse.  Most operating systems have a compatible interpreter making your script OS agnostic however there are some steps that must be preformed prior to deployment.  In addition, Python's interpreter adds a layer of processing to your code and as such, it can not attain the performance levels of other languages.  It's not all bad though.  Python has an elegant syntax and features dynamic typing making it the ideal language for complex code and rapid development cycle.  Additionally, the dizzying array of packages available can extend your scripts functionality quickly without having to reinvent the wheel.  If speed is your concern, calling functions written in C or C++ is possible and used in some of the standard library, most notably where processing large amounts of data quickly is important.

Python comes in two flavors.  Version 2 and 3.  Major changes were developed in the switch to V3.  V2 has reached the end of its service life and all new scripts should not use this older version.  You may run into some code in your web searches designed with V2 which is not compatible with a V3 interpreter.  As you learn V3  the methodology will become clear and you will start understanding how to transcode between languages.

Your development environment can be as simple as notepad where the code is written as simple text into a .py file.  This might work for the extreme beginner but I strongly suggest an environment which employs a linter (displays errors in syntax) and code completion (guesses what you are trying to say).  I personally use VS Code.  These will take a bit of effort to configure to your liking but invariably will save you loads of time and frustration.

To run your code you must call it from the command line.  Generally, you will call the Python interpreter with your script as an argument.  Sometimes it can be tricky but following the outline below should get you going.  Visit https://www.python.org/downloads/ to install python first.

Open your terminal and try the following:

python --version

python3 --version

python2 --version

if none of those work, you may have to add the path of your python installation to the Windows path variable or install the interpreter.  A quick web search on how to call python within your operating system should help you get there.