Python Introduction

In this post, we will see a simple intro to

Welcome Pythonists - What is Python and who uses it?


Python is a general-purpose, versatile and popular programming language. It's great as a first language as it is simple and easy to read, and it is also a good language to have in any programmer's stack as it can be used for everything from web development to software development and scientific applications..

World-class Organizations using Python include


Python Introduction - Notebook





IDLE Installation (optional)


If you alread have IDLE or other development IDE's, you can skip installing IDLE.

Visit https://www.python.org/downloads/ to download and install latest version of python with IDLE. As of writing this page, the latest version is Python 3.7.0. IDLE Shell will look something like the image below (We can customise the environment to suit our taste).

Python IDLE Shell

Time for Fun


Without talking any further, let's dive straight into the program and have some fun. Run the code below

import this

and you will see the output as shown below. The Zen of Python is a collection of 20 software principles that influences the design of Python Programming Language. It is included as an easter egg in the Python interpreter, which can be displayed by entering import this

The Zen of Python, by Tim Peters

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!

If you run the code below

print (this.s)

and you will see the output as shown below. Here, the Zen of Python is ceaser chipered by 13 places. For more details on import this module, ceaser chiphering & ROT-13, refer wikipedia or stack overflow.

Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!

To decrypt the above encoded module, you can run one of the 2 codes shown below.

import codecs
print (codecs.decode(this.s, 'rot13'))
print ("".join([this.d.get(c, c) for c in this.s]))

Installing packages using pip


Pip is a package manager used to install and manage softwares written in Python. You can access the pip from command prompt or terminal.

To check the pip version

pip -V
Pip version

To check whether a package is already installed

pip show package_name
pip show example

If the package doesnt exist, it will show nothing

pip show example

To install a new package

pip install package_name
pip show example

Python Packages used in this course


Mandatory pacakges

Optional packages


For Nerds and Geeks - Computer Hardware Architecture


Before we start learning the Python programming language to give instructions to computers, let's have a sneak peek of how computers are built. If you were to rip off a computer or cell phone and look deep inside, we would find the following parts:

computer_hardware_architecture

As a programmer, we will mostly be "talking" to the CPU and telling it what to do next by writing down instructions. We call these stored instructions a program and the act of writing these instructions down is called as programming.

For Further reading


To find what Python is all about, explore some of the links below:

Visit Python Tutor Visualizer to visualise the code and understand what happens behind the screen when each line of Python code runs. It shows the assignment of all the variables and the variale scopes graphically as shown below.

Python Tutor Visualizer

Next: Data Types, Operators, Variables, Input and Output »