Home Python Getting Started with Python

Getting Started with Python

Before we dive into the Python world, we must observe two important protocols. The first one is acknowledging its founding father, and the second one is introducing it into our operating system environment. The name Guido Van Rossum takes credit for the creation of the Python programming language. Python is regarded as a general-purpose programming language meaning its applicability is dynamic.

It was not just the invention of Python that directed programmable praises towards Guido Van Rossum as anyone can come up with a programming language. It was the uniqueness in the structure and simplicity of its code that caught the programming world’s attention. Python provides a cool application code responsible for:

  • Machine Learning
  • Data Analysis
  • Visualization
  • Financial Calculation
  • GUI (Graphical User Interface) Development
  • System Administration
  • Web development

A Walk Down Computing Memory Lane

To understand why Python is alive, we need a recap of the most basic machine code as we progress. We need to restart our journey up the hierarchy tree that sums up the evolution of programming languages. Let us start with the one that initiated the most basic communication with the machine hardware.

Machine Language

Some common human native languages are English, Hindu, Chinese, and Swahili. Humans are rooted in these native languages the same way a CPU (Central Processing Unit) is rooted in the machine language code. The code that defines a machine language is usually in a sequential string of 0s and 1s. A case example is when a CPU receives a string of instructions requesting it to initiate the summation of two numbers. An example binary code for this type of instruction is similar to the following display prompt.

0101010100001

If we take a screenshot of the activities that take place on a normal CPU day, we will find it working with hundreds of instructions. For the CPU to be effective, it will organize the said instructions into a single entity called an instruction set. Different CPU vendors functionally design their CPUs with different instruction sets. Vendors like the AMD family and Intel family use different instruction set algorithms to bring their CPUs to life. The difference in their instruction set distinguishes the performance attributes of these vendors’ CPUs, making them as unique as possible.

This approach was the initial mode of writing programs through the machine language code. You can imagine the involved complexities and time frames needed just to bring one program to life and execute it properly through the CPU. Moreover, reading and understanding of machine code was an uphill battle. Therefore, debugging and modifying the code was close to rocket science. The trials and tribulations of working with machine language then inspired the evolution of assembly code.

Assembly Language

Assembly code became a great improvisation for developers over the asocial machine code. It was a migration from writing instruction code in 0s and 1s to using actual letters, which constituted short descriptive words, understandable to an assembler. These short descriptive words defined mnemonics, and each mnemonic qualified as a viable machine instruction understandable to the computer. Therefore, an example of assembly language code that instructs a computer to add two numbers would be as simple as depicted below.

Add e, f

Comparing this assembly language instruction code to the one written in machine language code highlights a milestone of improvement in creating a human-friendly code instruction. The simplicity of the assembly language code made it even possible for the non-technical users to comprehend what the CPU was trying to achieve.

However, the cleanliness of the assembly language code structure only favored the humans and not the CPU. The same way it is difficult for anyone to forget or part ways with their native language is the same way the CPU felt when it was introduced with assembly code. It was not ready to be bilingual. Its love for binary then forced the introduction of assemblers. Consider two leaders from two different nations rooted in their distinct native languages. The same way they would need a translator to communicate is how an assembler’s functionality came to life. It acted as a translator and helped the CPU understand the assembly language code. Therefore, a code spoken in assembly language passes through the translator (assembler), which then speaks the same code in machine language for the CPU to grasp what is required.

Therefore every assembly code is passed through the assembler to be translated back to machine language code before reaching the CPU, with no exceptions. Therefore, a programmer’s life became smooth not because of the assembly language code but because of the assembler which understood both the assembly code and the machine code. Therefore, reading, modifying, and debugging assembly code was technically a roller coaster ride.

However, the evolutionary milestones of the assembly language also had its shortcomings.

#1) It was difficult to scale as coming up with a large scale program through assembly code was nearly impossible. There was no easy way of applying the assembly code to create larger applications with dynamic logic.
#2) The mastery of the assembly language code came at a cost. One had to have a thorough and in-depth understanding of the instruction set and architecture that constituted the CPU.
#3) There was a portability issue with using assembly code to write program instructions or logic. The program logic only favored the architecture of the CPU that was used to create it. Therefore, transferring the same program logic to a different CPU architecture was an impossible gamble.
#4) Even if you were able to figure a way out of the first three listed complexities, you will not recover the time used to navigate to the solutions of the stated challenges.

All these shortcomings in the assembly code are also viable in the machine code, except for CPU code readability, which is more efficient under the machine code.

From the information we have gathered and understood so far, both the machine and assembly languages have their specific demands. They require a user or a programmer to have prior knowledge and expertise of a computer’s hardware. Specifically, the computer hardware reference directly points to the mastery of low-level details like the CPU’s architecture. With such regard, these two languages earned the notation low-level languages.

Since humans always find a way of upgrading from previous challenges, the invention of high-level languages came into the picture.

The Sunrise of High-Level Languages

The high-level languages came into the limelight with a unique structural approach. This language construct did not want to bother itself with understanding the CPU’s thought-processes or hardware architecture. The new-generation mindset of the high-level language wanted to solve a computing problem rather than understand the current computing problem. The closeness of this language to the human language is close to genetic. It is another reason why it is easier for us to digest the content of a high-level programming language like a mystery novel. Since high-level languages also have code instructions, their rule book demands we refer to these instructions as statements. Therefore, an example statement to help us calculate the area of a rectangular would be as simple as follows:

area = 4 * 9

Before we move any further, let us first digest the benefits high-level languages bring to the table.

#1)You are spared the headaches of forcefully having to acquire a master’s degree in CPU architecture with the inclusion of understanding how their instruction set or code logic operates. The only thing you need to worry about is the industry or domain you wish to pursue with your high-level programming expertise.

#2) Since one CPU can’t tell you what to do with your portable high-level language program, you can pocket it and run it on any computer hardware you want.

#3) The early days had the bars raised too high for anyone wishing to explore a programming career. You had three options; you were either a computer scientist, a mathematician, or not a viable candidate. High-level languages have not only lowered this bar but also dismissed its existence. The only qualification that remains for a programming career is to have an eye for the price. The price is how far you want the programming tide to take you.

Since we’ve already covered statements, the next term in the rule book of high-level languages is source code. It is simply a naked high-level language program. Since the CPU still stubbornly refuses to be bilingual to loosen its grip on the native machine language code that defines it, it will not want to have any direct association with a high-level language. Therefore, we will also need the intervention of translators to explain the high-level language code to the CPU in its native low-level machine language code. Two translators will help us resolve this communication warfare. They are the compilers and the interpreters.

Compiler

This translator is smart and will read through the whole high-level language code and translate it for the CPU in machine code with a single read. The CPU will then be able to execute the program instructions. Any modification on the high-level code will cause the compiler to repeat its translation sequence. High-level languages associated with the compiler fall under the category of compiled languages. Some compiled languages include C#, Java, Go, C++, and C.

Interpreter

We can think of the interpreter as the translator that is also smart but patient. It translates the high-level language code to machine code for the CPU by reading one statement and then translating it before moving on to the next statement. The approach is different from the compiler’s way of reading the whole source code at once and then translating it. High-level languages associated with the interpreter fall under the interpreted languages category. Examples of interpreted languages include Python, JavaScript, Pearl, PHP, and Ruby.

Enter Python, An Interpreted Language

Finally, we have the long-awaited mention of the Python programming language. The above-mentioned information should be enough tribute to the evolution of the programming languages. The hierarchy tree we mentioned during this article’s introduction has branched us to a programming language category that safe-keeps Python.

Compiled languages like to show off in the face of interpreted languages because of their speedy performance benefits. However, it’s a daunting task to develop a decent program code in compiled languages because of their complex rules. Moreover, even the most basic function like splitting a string or determining an array’s length is the user’s responsibility. Dealing with data structures for advanced tasks is also an issue, as you will have to create your customized data structure versions to interact with your program’s data. Resolving such gritty details removes the joy of programming for most individuals.

Python makes programming seem like an adventure game with clued puzzles. Defining small utility functions and data structures is the role of Python. It won’t bother you with technical requests. Moreover, if you want to expand your library options, Python has hundreds on offer. Therefore, don’t stress yourself re-inventing the wheel.

Python Variable Data Types’ Dynamics

Python’s variable data types are a marvel to work with as you do not have to pre-define them. Python, by default, will understand the variable data type you are using based on the value you choose to assign it. Let us take the following example case.

thisvar = “Welcome to Python”

The code statement has the value “Welcome to Python” and the variable thisvar. Python assumes the variable type to be a string due to the enclosed nature of its value, which is in double quotations. You should also note that Python statements do not end with a semicolon notation.

thatvar = 3

If we create another variable thatvar and assign it the value 3, Python will assume the variable to be of type int or integer. Therefore, Python has its smart way of figuring out the variable data types we use in our programs once we declare them in a statement.

Python as a Strongly Typed Interpreted Language

The landscapes of JavaScript and PHP programming languages handle data type conversions differently than Python despite being in the same interpreted language category. Their conversions are automatic, and this trait classifies them as weakly typed languages. A more practical approach to this case scenario is the result instance of the following JavaScript code.

2 + “3”
The JavaScript interpreter will typically output:
‘23’

A breakdown of the JavaScript interpreter’s understanding of the above code statement is as follows. The interpreter disregards the addition sign and firstly converts the integer 2 into a string. We now have two strings, “2” and “3,” representing the code statement. Finally, the addition sign gets interpreted as a concatenation leading to the output ‘23’, which resulted from merging the two mentioned strings.
However, trying to execute the same code statement in a Python environment will result in an error. The Python interpreter will not allow the addition of two distinct variable data types. This trait portrays it as a strongly typed language.

Python’s ‘Less Code More Action’ Slogan

If you compare two basic codes in Python and Java that achieve the same result, it will not be a surprise that Python’s code lines will be less than Java’s lines of code by 2/3 or 4/5. However, the two programming languages will still mock similar ideal performances. For instance, a simple Python code to read a random text file will only require two code lines, as illustrated.

with open(“randomfile.txt”) as f:
print (f.read())

This code example is just an illustration as we will need to configure some basic tweaks for it to execute fully.

Deciding Between Python 2 and Python 3

You might be a beginner programmer or someone who has finally decided to join the Python hype. Preparing for the first Python roller coaster adventure sometimes starts with the Python version headache. Therefore, your go-to Python version should always be Python 3. It is because it comes with a fix to the drawbacks possessed in Python 2. Python 3 is futuristic and more polished. Moreover, it does not support backward compatibility; hence Python 2 cant run Python 3 apps.

Now that you understand what python version you should use on your machine, you should follow our tutorial module on installing Python 3 on your Linux system.

Final Note

Python is not only a high-level programming language but also an empowering tool in the 21st century’s software development segment. Web applications, web services, desktop applications, APIs, AI, and Machine Learning, are turning towards Python for a scalable insight. Large organizations like Quora, Google, HortonWorks, and NASA are already embracing it. The first step in beginning any great endeavor is matching away from the starting line. May your Python thirst continue to grow as you translate your Python dreams to your CPU.

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More