Python, Python Tutorial, Software Development

Chapter 1: Introduction To Python 3 That Does Not Bite

Python is a general-purpose programming language that is available in many operating systems.  When we run a Python program, we run it using the Python interpreter. However, there is more to that than meets the eye. The Python interpreter reads the codes and compiles them to bytecodes. Then, the interpreter uses those bytecodes to execute the whole program. This post is an introduction to Python 3.

Introduction To Python – Who, When, And Why?

Believe it or not, Python is an ancient programming language. It was created in the late 1980s by Guido van Rossum. Now, the reason he created Python is not something most of us can relate to nowadays, but it is worth knowing.

Guido’s Write Up on USENET

Below a write-up from the author, he posted on the USENET.

I had extensive experience with implementing an interpreted language in the ABC group at CWI, and from working with this group I had learned a lot about language design. This is the origin of many Python features, including the use of indentation for statement grouping and the inclusion of very-high-level data types (although the details are all different in Python).

I had a number of gripes about the ABC language, but also liked many of its features. It was impossible to extend the ABC language (or its implementation) to remedy my complaints — in fact its lack of extensibility was one of its biggest problems. I had some experience with using Modula-2+ and talked with the designers of Modula-3 and read the Modula-3 report. Modula-3 is the origin of the syntax and semantics used for exceptions, and some other Python features.

I was working in the Amoeba distributed operating system group at CWI. We needed a better way to do system administration than by writing either C programs or Bourne shell scripts, since Amoeba had its own system call interface which wasn’t easily accessible from the Bourne shell. My experience with error handling in Amoeba made me acutely aware of the importance of exceptions as a programming language feature.

It occurred to me that a scripting language with a syntax like ABC but with access to the Amoeba system calls would fill the need. I realized that it would be foolish to write an Amoeba-specific language, so I decided that I needed a language that was generally extensible.

During the 1989 Christmas holidays, I had a lot of time on my hand, so I decided to give it a try. During the next year, while still mostly working on it in my own time, Python was used in the Amoeba project with increasing success, and the feedback from colleagues made me add many early improvements.

In February 1991, after just over a year of development, I decided to post to USENET. The rest is in the Misc/HISTORY file.

What is Python 3?

Python 3 is the eternal latest version, although there is a plan for version 4. Python has had only three versions since 1991, unlike (most) other programming languages. Although some operating systems come with Python 2 by default, it is best to start using Python 3 instead – Python 2 has already reached its EOL in January 2020. That means there will no longer be future developments or bug fixes for the old Python. Also, Python 2 and Python 3 codes are not compatible. Python 2 codes will not run in Python 3 and vice-versa. So, no need for Python 2 introduction.

Python Is Also A Platform

Python is not only a programming language but also a platform. If we had installed Python locally, we could see the following files in its home directory.

The file python.exe is both an interpreter and platform for running Python programs. As an interpreter, it can be interactive! Meaning, we can run codes on the fly on a command prompt. If we run the python.exe, we will get the following interactive interface.

We can run Python codes as follows.

To exit from the interpreter, type exit() and press the Enter key.

To run a Python source code file, we pass the filename as an argument to the python.exe program. Let us say we have the following codes in a myapp.py source code file.

The following command will run our application, myapp.py.

We get the following output.

Python Is Object-Oriented

Object-oriented programming is a style of coding that deals with objects that we create from a group of codes that hold data and have functions to operate on the data. Python is an object-oriented programming language that supports the following object-oriented concepts.

Classes

Python classes are groups of codes that hold data and have functions to operate on the data. They are the blueprints of objects. Python allows us to group codes into classes.

Objects

Objects refer to instances of classes. While classes are codes, objects are runtime representations of classes. Python supports the creation of objects from classes.

Inheritance

Inheritance revolves around the concept of parent and child classes. Child classes can derive their functions from parent classes. Meaning they can have the same set of functions as their parents have. Python allows us to define parent-child classes.

Abstraction

Now, this is hard to associate with Python. Abstraction means data hiding, and access to them must be through functions. Although we can hide data in Python classes using the private access modifier, the data is still accessible. See the last section of this Python introduction post.

Python Is So Easy To Learn

Many consider Python as a beginner’s language because of the language’s keywords and syntax simplicity. Using them is like using natural language to express thoughts and actions. Also, the Python codes are generally less cryptic than codes from other programming languages.

Python Is Somewhat Inconsistent In Some Places, Bear With It

Learning Python has its undesirable pieces of baggage that are somewhat non-conventional (or weird) implementations if you are coming from programming languages like Java and C#. Consider the following codes about private property in a class.

We create private class properties in Python by prefixing variable names with double underscores. Most programmers from Java and C# would expect the property to be inaccessible outside of the class. However, we get the following output when we run the codes.

We were still able to change and access the class’s private property. Overall, Python is still worth learning because many people and companies are using it.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like