Learn Python Programming – Intro

By | October 28, 2020

Hey guys welcome back, in this series we are going to learn about Python programming. Python has been in demand ever since data analytics has been in limelight. Python has existed from a long time however, with data analytical capabilities Python has grown even bigger. I’m sure you will have a question here – I don’t do data analytics, is Python for me ? Sure it is. Python is an Object Oriented Programming language, it has strong data analytical capabilities but it doesn’t mean it can be used only for that. From the wide varierty of languages I have learnt or heard about, Python is one of the easiest language to understand. So without talking much lets learn Python Programming.

Topics to be covered

In this series we will focus on beginners and when I say beginners it can be people who have no or very little programming experience. Below are some of the topics we will try to cover in this series (will keep on adding as we move ahead in this series):

Python 2 vs Python 3

As the number suggests, Python 3 is the latest and an obvious choice in most of the cases. However, you can still find applications running on Python 2. One of the modern era technology where Python 2 is still used is configuration management of DevOps. Python 3 is referred to as more optimized and more user friendly.

Some of you who have already worked in Python 2 will know that print “Hello” from python 2 has changed to print(“Hello”). This might seem like an addition of paranthesis alone but changes a lot on how python works because print “Hello” is a statment, whereas print(“Hello”) is a function. Another example of change is the default strings storage. Python 2 uses ASCII standards which stores all english characters, whereas Python 3 used UTF-8 (Unicode Transformation Format – 8-bit) which gives users flexibility to use a lot more characters than just english language. The changes might sound trivial but Python 3 is definitely a forward looking version.

Python 2.7 version bridges a lot of gap between Python 2 and 3. A lot of Python 3 code can be run on Python 2.7 version without any modification, however it might not run on versions (2.6 or lower) prior to that. To conclude I must say until you setup environment doesn’t allow you to install Python 3 I see no reason to use Python 2.

Installation

Let’s quickly get into installation of Python, in this post we will cover about Windows installation but the process doesn’t differ much on Mac or Linux.

Step 1 : Go to https://www.python.org/downloads/ and link to the latest version will be on the top. You can also scroll down for previous releases, I would recommend always using the latest version.

Download Python

Step 2 : Once you have the file downloaded, installation will be as simple as clicking few next buttons. Make sure you click on checkbox “Add Python 3.X to PATH”. With this being checked installer adds the path of the installation directory to the system variables. This will ease your access of python commands from CMD prompt.

Install Python

Once the setup is complete, you will see a window like below:

Python Setup Complete

Step 3 : That’s it, you are all set you to use Python on your machine. Open up cmd prompt and you should be able to check the version installed:
command : python –version

Python Version  - Learn Python Programming

Understanding and Setting up environment/IDE

Python comes with a inbuilt IDE which is called IDLE (Integerated Development and Learning Environment). You can you this as your IDE or install other fancy things like PyCharm. PyCharm provides a GUI for basic python stuff and makes thing easier for example if you import a package which is not yet installed PyCharm will give you a bulb like icon to install instantly insteading of writing pip commands. Though PyCharm works perfectly fine it sometimes become difficult to install these fancy editors in restricted client environments and hence for this series we will use either IDLE or basic code editor like Visual Code and terminal.

IDLE  - Learn Python Programming

Running Python Programs

IDLE looks very simple and you can just start writing Python Commands to it. Lets start with everyone’s favourite “Hello World”.

IDLE Hello World  - Learn Python Programming

The above image is pretty much self explanatory, we just have a simple command : print(“Hello World”). Print is a function in Python which takes input on what needs to be printed and if you notice on the next line “Hello World” is printed. If you want to save this file for future reference or make changes to it you can do so by going to File>Save Menu options. Python files are saved with an extension .py

IDLE Save Menu  - Learn Python Programming

Command Prompt can also be used to run python directly. You just need to write a command python which will open a python terminal and you can continue working as in IDLE.

CMD Prompt Python  - Learn Python Programming

If you have a file which contains some python code you can call that file in command line as : python <filename.py>

Excute Python from File  - Learn Python Programming

Note : “#” in Python denotes a comment line

Conclusion

So this is it from this article, we learnt about Python and the key differences between Python 2 and Python 3. Also, we looked into installation and setting up of the IDE. We also wrote our favourite Hello World program. In the upcoming articels we will learn python programming in details, untill then stay connected.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.