Introduction to Python Programming. Section 1. Introduction
In this section you will learn:
- About compiled and interpreted programming languages.
- The history and basic facts about Python.
- How to access the NCLab virtual desktop and open the Python app.
- How to use the Python app to write and run your Python programs.
Python is one of the most attractive programming languages that one can learn today. It is an undisputed leader in areas of the future such as big data, machine learning, and artificial intelligence. Python is easy to learn and incredibly versatile. It can be even used by non-programmers as a scientific calculator and powerful data analytics and visualization tool. It is almost unbelievable how Python is starting to dominate fields that traditionally belonged to specialized (and expensive) software products. As an example, let us take the area of data analytics which was traditionally dominated by SAS. We are going to show you two graphs. The first one, presented in Fig. 1, was taken from the webpage of Analytics Vidhya (https://www.analyticsvidhya.com). It shows that the number of job postings asking for R already surpassed the number of job postings asking for SAS:
The second graph presented in Fig. 2 shows that the number of data analytics job postings asking for Python is much higher than the number of job postings asking for R.
Another example is general computing which for decades was dominated by MATLAB.
Nowadays, powerful free Python libraries such as Numpy and Scipy, accompanied by
advanced data visualization libraries such as Matplotlib, Mayavi and Seaborn, are taking
over this area as well.
In this textbook you will learn the most important aspects of the language and you will be able to use Python to solve a large variety of practical problems. Depending on your objectives, Python may be the only programming language you will ever need. We hope that you will like Python as much as we do, and that after finishing this textbook you will want to learn more – and there always is much more to learn.
Python is an interpreted (as opposed to compiled) programming language. Let’s briefly explain what these words mean.
Compilation is a process where human-readable source code (text) is translated by means of a compiler and a linker into a binary (executable) file which then can be run on the concrete computer. The same source code, compiled on different hardware architectures, yields different binaries. Compiled programming languages include Pascal, C, C++, Fortran, Java and many others.
Interpreted (scripting) programming languages are more recent than the compiled ones. A program that is written using an interpreted language is "read" (parsed) at runtime – it is not compiled and there are no binaries in the traditional sense. Programs written using compiled languages are usually more efficient than programs written using the interpreted ones because the former take better advantage of the underlying hardware. On the other hand, interpreted languages are usually more universal and easier to use. Examples of interpreted languages are Python, Lua, Perl, and Ruby.
Python was conceived in the late 1980s by Guido van Rossum in the Netherlands. Its implementation was started in December 1989. The name of the language comes from the British television series Monty Python’s Flying Circus. Python 2.0 was released in October 2000 and Python 3.0 in December 2008. The newest version to-date, 3.6.5, was released on March 28, 2018
Python was twice awarded the TIOBE Programming Language of the Year award (in 2007 and in 2010). This award is given to the language with the greatest growth in popularity over the course of a year.
Python is a multi-paradigm programming language. Rather than forcing programmers to adopt a particular style of programming, it permits several styles: structured (procedural) programming and object-oriented programming are fully supported, and there are a number of language features which support functional programming.
NCLab (Network Computing Lab) accessible at http://nclab.com is a public cloud computing platform that provides many apps related to computer programming, 3D modeling (CAD design), scientific computing and publishing, computer simulations, and other areas. It also provides self-paced and self-graded courses. Take a moment to visit http://nclab.com and create a user account now.
We will be programming using the Python app which is available in the Programming section of the Creative Suite as shown in Fig. 3. The Python app allows you to write, run, and debug your programs in the web browser, save them in your NCLab user account, and access them from any web browser, including tablets and other mobile devices. You can also upload data files to your user account, download your programs to a hard disk, and publish your programs to share them with others.
In order to use NCLab, your device needs to be connected to the Internet. Initially, the Python app will launch with a demo script - a program which you can just run and see the result. By pressing the Play button on the bottom of the window, the code is sent to a remote cloud server, evaluated, and the results are then sent back to your web browser. This process usually takes less than a second, unless your Python program needs a longer time to run. After you do not need the demo script anymore, you can turn it off in Settings. The Python app can also be launched directly by double-clicking on a Python program in the File Manager.
Since the amount of transfered data is relatively small, working in NCLab does not put much strain on your Internet connection. The connectivity requirements of NCLab are comparable to reading your emails.
It does not matter if you are using a desktop computer, laptop, chromebook, tablet, or any other hardware platform. Your device is not used for computing - only when you work with graphics, then your graphics card may be used for image rendering. For practical reasons we do not recommend using NCLab on your phone - the phone’s display is simply too small to create an enjoyable experience.
Table of Contents
- 1. Introduction
- 2. Using Python as a Scientific Calculator
- 3. Drawing, Plotting, and Data Visualization with Matplotlib
- 4. Working with Text Strings
- 5. Variables and Types
- 6. Boolean Values, Functions, Expressions, and Variables
- 7. Lists, Tuples, Dictionaries, and Sets
- 8. Functions
- 9. The ’For’ Loop
- 10. Conditions
- 11. The ’While’ Loop
- 12. Exceptions
- 13. File Operations
- 14. Object-Oriented Programming I – Introduction
- 15. Object-Oriented Programming II – Class Inheritance
- 16. Object-Oriented Programming III – Advanced Aspects
- 17. Recursion
- 18. Decorators
- 19. Selected Advanced Topics