Getting Started with Python


This is a part of the series of posts on Python Crash Course. This is the first step, in learning Python - that can introduce you to the language.

As per the StackOverflow survey, Python was the fastest growing programming language of 2019. And we can expect this trend to grow as the developer community continues to move towards Python. That makes Python the language of choice for any developer.

Installation


There are many different sources and distributions of Python. Foremost is available on their own site Install Python. This page has everything you need. Download the version you like.

For legacy reasons, Python continues to host the Python 2.* installers. But, also warns us that it will be deprecated very soon. This "soon" has not arrived over the last 4 years that I have seen their page. But, from the trends we can say that, anyone serious about the future, should use Python 3. Specially if you are learning afresh, there is no reason to go for Python 2. (Unless you are forced to maintain a legacy Python 2 application).

We also have other distributions like Anaconda that package a good amount of useful stuff along with the base Python. This is what most enthusiasts use. And then there are other commercial distributions of Python like ActiveState Python that charge you for support and packaging. That is meant for people who prefer to spend money.

Python comes with its own editor (IDLE) that provides syntax highlighting. It is good for developing and running minor scripts and also for testing single commands. But, for doing anything more complex and useful, you will need a better IDE. Several open source IDE's are available on the net. The list keeps growing. Just lookup one you like from Google and you should be ready to go. I liked PyCharm, Spyder, Atom and Visual Studio Code. If you don't like these, just search for one on the net and let me know if you find something useful.

Hello World


We often put in a lot of effort on Traditions. We do a lot of things we don't really know why, but we do them because "that is the way"! The "Hello World" is another such tradition. None knows what is so magical about those two words. But there is something so magical that everyone wants to use just that phrase.

Anyway, let's do the same here - announcing to the world that we have started learning Python.Open your IDE and create a new Project - Learn Python or HelloWorld; Create a new file with the appropriate extension (.py).

If you are running on Windows, the extension should be enough. But if you are fond of Linux, the extension has no meaning. You need to explicitly indicate the interpreter using the shabang on the first line of the script. After that, add the following one line in the new script.

#!/bin/python
print("Hello World")

(The shabang would point to python or python3 depending upon the Python distribution that you use.)

That is all we need in order to start. The code prints the two words - Hello World - Nothing much for the world, but it does tell you that you have started well!

Congratulations! You have started off on your journey with the Python. Now follow along as we see how the Python has engulfed the world, and grown into an Anaconda!

Zen of Python


Before we jump into the code, it is important to understand the core values that are expected of a Python Programmer. Python language was created with some important principles in mind - that were lacking in other languages. These principles are the key to its success, and are called the Zen of Python.

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Sparse is better than dense.
  • Readability counts.
  • Special cases aren't special enough to break the rules.
  • Although practicality beats purity.
  • Errors should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • There should be one-- and preferably only one --obvious way to do it.
  • Although that way may not be obvious at first unless you're Dutch.
  • Now is better than never.
  • Although never is often better than *right* now.
  • If the implementation is hard to explain, it's a bad idea.
  • If the implementation is easy to explain, it may be a good idea.
  • Namespaces are one honking great idea -- let's do more of those!

For the uninitiated, these may seem stupid and silly. But someone who has seen and worked on an application with a million lines of code will certainly appreciate their value.