An Introduction to Python

WHAT IS PROGRAMMING?

Have you ever thought about how your computer works? Computers, Mobiles, or any electronic gadgets are just ordinary devices that cannot do anything independently. We have to make these devices useful. How can we do that? The simple answer to this question is — BY PROGRAMMING (and of course, you need a power source for running the devices :P).

So, programming is giving instructions to the computer and power supply is a mode of keeping your computer on and running. There is a brief history of how we got to land at programming and its total evolution. If you are interested in knowing then you can follow this Wikipedia and power supply is a mode of keeping your computer on and running. There is a brief history of how we got to land at programming and its total evolution. If you are interested in knowing then you can follow this Wikipedia link . .

Python is one of the many programming languages, which is used to provide instruction to the computer in order to get a job done. For example, if I want to make an automated schedule that will have a to-do list and will remind me of those to-do things automatically at the exact time, then I can use Python to make that automated schedule. See! How good it is! You do not have to worry about memorizing the schedule. Python can do this and a lot more things for you.

WHY PYTHON?

Python is a Hight Level programming language. Python is easy to get started with and has a huge scope in terms of its usage. Python has simple concepts, yet many powerful ones. Although Python is easy to learn, you will get to know the potential this language has got in the long run. So what you can do with Python? To name a few, you can -

Also, there is a huge demand for Python coders in today’s technical world, making Python stand among the top 3 programming languages to learn and work with. So, let’s get started with Python.

HOW DOES PYTHON WORK?

Computers cannot understand our language. It only knows the language of 0 and 1. That is whatever we want the computer to do or whatever instructions we provide to the computer, has to be converted into 0s and 1s for the computer to understand and work accordingly. But, we humans do not speak in terms of 0s and 1s. So we need something that can do the conversion for us.

Python, just like other languages of Java, C, etc, does this conversion for us. So whatever we code in Python, we do it in the language of English and then that code (written in English) gets converted to 0s and 1s for the machine to understand. This is a very top overview of how it functions.

So, someone has already done the hard work for you in teaching the computer about the meaning of the codes you will write in Python. However, this does not take place in a single step. The conversion takes place in two steps and that has significance as well. Let’s see how it is done -

Python codes are having the extension of .py, just like presentations have .pptx, pictures have .jpg, .png, etc. In order to write python code, you need an Integrated Development Environment (called IDE), in which you can Write and Run the code. You can also use the normal notepad to Write the python code but make sure to save the file with an extension of .py, and then for running the code you will need Python IDLE. Now, what is Python IDLE? IDLE is is Python’s Integrated Development and Learning Environment, where you can run the code and see the output instantly for every line (we will cover this later). Integrated Development and Learning Environment, where you can run the code and see the output instantly for every line (we will cover this later).

Hence, we can see that Writing and Running python code is needed. Now, you can write the code as mentioned above. Then for Running the code you need to have IDE or IDLE. Why is it so? Because these things come up with Compiler and Interpreter . In order to make the computer understand your instructions written in Python, the code has to be compiled and then interpreted. So what is this compiled and interpreted? Let’s see - . In order to make the computer understand your instructions written in Python, the code has to be compiled and then interpreted. So what is this compiled and interpreted? Let’s see -

The compiler is a mechanism that will compile your code all at once. Compiling code means converting the whole code into the byte format. A compiler is a pre-built tool that comes with the installation of python. Now the byte code is interpreted using the Python interpreter to convert the code into machine code. So, the Interpreter converts (or we say interprets) the byte code line-by-line into machine code, and the compiler converts (or we say compiles) the Python code all at once into byte code. Now, what is this machine code? These are nothing but 0s and 1s instruction formats. So, the conversion goes like this -

WHY DO WE NEED TO HAVE THE BYTE CODE?

Having a byte code is necessary for code sharing. Python compiler is compiling the code into byte code which is machine independent, that is it does not matter which machine you are on (be it Windows, Linux, etc.), your byte code will run on any machine, provided you have the Python interpreter for that machine. Sounds confusing? Let’s take an example -

Suppose there are two coders A and B. A uses Windows and B uses Mac OS. However they have to work together on a similar project, hence code sharing is needed. A wrote a code that calculates the total marks of students, then compiled the code and generated a byte code. B has to calculate the average scores for the students. So B takes up the byte code and runs it on the IDE, thus he gets the total score calculation program and he just has to add the average score program. Then B runs the program which gets compiled again (as new code is added, so it will get compiled with the old code), and another byte code is generated which then is interpreted into the machine code and the computer or the machine gives you the result you needed. So, the byte code is machine-independent. The byte code generated on Windows by A is used on Mac by B. The compiler and interpreter are machine-dependent, that is you will get different python packages and IDE for different operating systems. Hence, this makes sharing and working better.

Now you may think, why not share the original python code? Well, we do share the original python code via several platforms like Github, bitbucket, etc. However, if you have to pass the code without the help of any platforms, then passing it in the form of byte code is preferred for the compilation to be done for that shared part (so it saves the compilation on the other side which in turn saves memory usage) and your code will be in the unreadable format as byte code is unreadable to humans. This is just a simple example of code sharing. However, this approach is followed for several important projects (which are secret as well).

CONCLUSION

You need to download and install Python in your system, be it windows, mac, or anything. You can get it from here . Download the latest version and follow the instructions while installing. . Download the latest version and follow the instructions while installing. Make sure to mark the box of ‘Add to the path’ if it is not already marked while installing. There you go! You have your python in your system. There you go! You have your python in your system.

Go to search and then to command prompt (cmd) in Windows (go to respective terminals in your OS). Type the code -

python — version

(pip double dash ‘-’ version and python double dash ‘-’ version). This will show you the version of the packages you have downloaded. You will get to know more about pip on the way. It is basically a python installation package that comes with Python when you install it. For now, you don’t have to worry about pip and can start exploring python.

We are done with the basic theory of Python. Now we can get started with the programming. Let’s build fun together!