Python Programming Tutorial

Welcome to the world of Python programming. Here you'll learn Python, not only by theory, also by codes. That is, whenever the practical programs needed for the topic, I've included along with its respective output.

Note - All the codes written in Python here, are well tested using one of the most famous IDE used for Python, named PyCharm.

Note - Before starting the tutorial of Python programming, let's first read all the things provided here very carefully to understand all about Python programming, along with answers of some interesting questions related to Python. I know it will take your crucial time, but trust me, you're investing your time in a right path.

So before starting the series of Python programming tutorial, let's see some world-class application written in Python or some big Multi-national companies (MNCs) that uses Python programming.

Applications Written In or Uses Python

In IT sector, one of the top company named Google uses Python for its system administration and system building purpose. There are extensive number of applications written in or uses Python programming language. In which these are the list of some famous and well-known applications all over the world:

  • YouTube - uses Python programming as its Back-end (server-side) development, along with some other languages that are C, C++, or Java, and Go.
  • Google - uses Python programming as its Back-end, along with other languages such as C, C++, Java, Go, and Node
  • Facebook - despite of PHP being the core language of Facebook, they also uses Python as its Back-end development, along with other languages such as C++, Java, PHP (HHVM), Hack, Erlang, D, XHP, and Haskell.
  • Similarly Yahoo, Pinterest, Spotify, Dropbox, NetFlix, Reddit etc. also uses Python.

Even NASA and SpaceX uses Python programming language for many purposes like testing, automation etc.

If these multi-national companies uses Python, then there must be a big reason behind it. Those big reasons are covered in the What is Python used for ? section, given below. Most of the time, many companies that are using Python because of its versatility and dexterity.

What is Python ?

Python is:

  • an interpreted high-level
  • general-purpose
  • object-oriented
  • procedural
  • functional
  • structured
  • and reflective

programming language. Before going the brief history of Python language, that is, who, where and when the language was developed. Let's talk about some questions, asked by many beginners before start learning Python.

I've answered all those questions related to Python programming, that provides the clear-cut understand on the language, that why and for what the language is used.

That is, if you're learning Python or wants to learn Python, then it is must to know the thing that tells, is it good to invest time in learning Python programming ?
Let's find out.

Why to Learn Python Programming ?

Despite of many reasons provided below (after this section) to learn or inspire you to learn Python programming, the main reasons are:

  • It has extensive community, means that, if any problem gets arise while doing the program in Python or doing any project or whatever you're doing in Python. You can find and get the solution from any where, over the internet because of its large number of community.
  • Python has a large number of libraries, that helps to cater all your need
  • Python is a highly flexible language, means that it can be used to develop a program works on multiple purposes
  • The development speed of a Python program is faster than other languages as it uses less code more productive

Note - Python is one of the most in-demand language all over the world.

What is Python used for ?

Python can be used for many purposes, in which these are the list of some common ones:

  • Web Development - Python is increasing its area in the field of web development too. Using Python's famous web framework say Django or Flask, you can write fast and secured Back-end code for your web. From all the web frameworks provided by Python, Django is the most famous and widely used. Also it is highly-scalable. Even Django like full-stack web framework, can be used for front-end too.
  • Data Science - Python programming also helps to develop an application that extracts knowledge and insights from both an unstructured and structured data across broad range of applications. Scrapy is one of the most used data science library in Python, used for Data Mining. Now-a-day, web scrapping application are also getting developed by many stealer too, to scrap the things from Internet. Whereas NumPy, Pandas, and TensorFlow are the three most used data science libraries in Python programming, used for Data Processing and Modeling.
  • Machine Learning - NumPy and SciPy are the two famous libraries that can be used in the field of machine learning using Python. Basically machine learning is a step to artificial intelligence. Like human learning, that You're or I'm learning the things, machine can also learn using data statistics and whatever you want to provide.
  • Artificial Intelligence - This is the field where I think Python dominates almost all the other programming languages. As Python is trending in Artificial intelligence. It is I think the most used language in this field. The Pandas and SciPy are the famous and widely used libraries in the field of artificial intelligence using Python.
  • Data Visualization - Python programming can also be used to create data visualization applications. Data visualization means representing the data or information in the form of graphs. Matplotlib is one of the famous library that can be used for data visualization in Python.
  • Operating System Applications - Application for operating system such as command line application, system administration, business application etc. can also be developed using Python programming language.
  • Desktop GUI - In Python, Tkinter is one of the famous Python programming package that can be used to develop desktop Graphical User Interface (GUI) applications.
  • Mobile Application Development - Kivy is one of the famous framework used to develop mobile application using Python programming.
  • Video Games Development - Pygame is a library used in Python to develop multimedia related things like video games. Scripting engine of the game can also be written using Python programming.
  • Bots - Bots can also be created using Python programming. Bots are helpful to deploy an automated task over the internet or wherever the programmer need to deploy. Bots works only on pre-defined tasks.

That is, the main use of Python programming is to develop applications for:

  • testing
  • monitoring
  • task automation
  • data analysis
  • data visualization
  • scientific apps
  • etc.

Is Python Easy to Learn ?

It depends on your skills. Means that, if you've basic understanding of any programming languages such as C, C++, or Java etc. Then learning Python becomes an easy task for you. That is, it becomes very easy to understand the code written in Python.

The only difference is to understand is its syntax like the for loop used in Python is a way different from these languages. The conditional statements are also different. And it should be, because it is a different language. But the main work or task of all the things like loops or statements or any other things like functions, classes, etc. are same.

Therefore if you have the basic command on any programming language, then learning Python is becomes like learning HTML. But some time you'll get some difficulties in understanding the code. But don't worry, I've written the explanation of each and every code given here.

And if you've not learned any language before, then you need not to worry. Because Python is so simple, even printing Hello World in Python can be written using a single statement as shown below, unlike most of the other languages that takes multiple lines of codes, even for printing your first name:

print("Hello World")

That's it, this prints the string Hello World on the screen. Now you're getting the idea about the language's simplicity. Therefore, just start the series without any hesitation, whoever you're. That is, all programs written in Python here, are easily understandable by beginner too as I've explained each and every code along with its output. And trust me, most of the time, you'll understand the code without reading the explanation of the code.

Note - Sometime, while I'm reading the code written in Python is like I'm reading the book. It seems like funny, but again trust me, after sometime, you too get realized why I'm saying this.

How Much Time does it Take to Learn Python ?

Well, it depends on you, that how long or how deep you want to go in Python. But the basic version of Python can be learned mostly in a week, a month or two, depends on your skill. If you're a programmer, then it takes hardly 2 months to complete the basics of Python.

But to be professional or to be an expert programmer in Python, you need to give some good time to it. Also you need to practice each and every code given here along with your self-practiced code.

Is Python OK for Beginners ?

Since Python programs are less wordy, therefore it becomes easy to understand for beginner too. After seeing less amount of codes to do a program, more confident automatically build up in beginner's mind. Basically Python provides English-like codes, that is, sometime feels like reading the book. For example, the code given below adds two numbers in Python:

a = 10
b = 20
sum = a+b

If you read the code, it is like, a is equal to 10, b is equal to 20, sum is equal to a+b, and finally print sum. That is, a+b becomes 10+20, so 30 is the output produced by above program using print() function. That's it. See how easy Python is :). The above program can also be written as:

a, b = 10, 20

both the program given above produces 30 on output. You see, how easy the Python is. Don't worry about the first statement of the second program or the whole program, if not getting idea. Because, this is just a demo, you'll get to know each and every thing about codes written in Python one by one in upcoming tutorials.

Why is Python so Popular ?

Because of its flexibility, scalability, rapid development, and excellent performance. Also the popularity of Python is increasing day by day, as it is an easy-to-learn programming language with its simplified syntax.

The answer to this question is I think already covered in the section What is Python used for ?, that makes Python so popular language.

Can Python used for Hacking ?

Yes absolutely, Python is a very powerful language to work on in creating codes for hack purposes. And I must tell you that Python is one of the most loved language used by hackers all around. As it is an open-source language and has extensively great number of libraries.

As I've answered all the questions that must be asked before starting the series of Python tutorial, now it's time to get the background of Python, that who, when and where the language was developed and all such details.

Who developed Python ?

Python was developed by Guido van Rossum, a Dutch programmer.

Where was Python Developed ?

Python was developed at Centrum Wiskunde & Informatica (CWI), a National Research Institute for Mathematics and Computer Science. This institute is located at Amsterdam Science Park, Netherlands. This institute is popularly known for the creator site of Python programming language.

When was Python created ?

Python was first appeared in February 20, 1991.

What are the Filename Extensions for Python Source Code ?

Python allows multiple extensions that can be used to name the file. Here I've provided three filename extensions that can be used to name the source code or program written in Python:

  • .py - The most used filename extension. I've used this extension for all the Python program created here.
  • .pyi
  • .pyw

For example,

What Languages was Python Influenced by ?

Python programming language was influenced by many programming languages such as C, C++, Java, Perl, Ada, and Lisp etc.

Which Languages are Influenced by Python ?

Many number of programming languages that are influenced by Python, in which some famous languages are JavaScript, Ruby, Swift, and Go etc.

Brief History of Python

The first release of python version was Python 0.9.0 in 1991. Python 2.0 was released after almost 19 years, that is at the date 16 October, 2000. Whereas the python 3.0 was released after 8 years since the version 2.0 was released, that is in 2008.

Note - The python 2 was discontinued with 2.7.18 version of Python in the year of 2020.

Note - Today is 02 September, 2021. And as of now, the latest version of Python is Python 3.9.6, released on 28 June 2021. But as official said, there is another latest version of Python is coming today, that is python 3.11.0a0. Therefore, while you read this article, this version or more latest version may be seen.

Note - Python 2.0 (16 October, 2000) - Python 2.7.18 (20 April, 2020). Python 3.0 (3 December, 2008) - Python 3.9.6 (28 June, 2021) and to be continue...

What are the Design Philosophy of Python ?

These are the list of core or main aspects that was kept in mind while designing or developing the language "Python". That is, the main design philosophy of Python are:

  • Beautiful is better than ugly
  • Simple is better than complex
  • Explicit is better than implicit
  • Complex is better than complicated
  • Flat is better than nested
  • Sparse is better than dense
  • Now is better than never
  • and many more

Some Famous IDEs for Python

To program in Python or to develop an application using Python, we need an integrated development environment or in short IDE. Therefore, I've provided some list of famous IDEs specially used for Python programming. Those list of IDEs are given below along with its essential details like how much disk space the IDE take, in which language the IDE written in etc.:

IDE Disk Space (MB) Written in Supported OS
PyCharm 600-800 Python and Java Windows, MacOS, Linux
Eclipse 150-200 Java and C Windows, MacOS, Linux
PyScripter 50-150 Python, Delphi, Object Pascal Windows
Atom 87-180 CoffeeScript, JavaScript, Less Windows, MacOS, Linux
Spyder 50-100 Python, Qt Windows, MacOS, Linux

Some more IDEs for Python are Emacs, PyDev, MS Visual Studio, Thonny, and Wing etc.

Note - PyCharm is the most used IDE for Python. Even I'm using this IDE since last 4-5 years.

Famous Web Frameworks for Python Programming

There are plenty of frameworks available in Python. But from all, let's list out some famous and most used web frameworks for Python programming.

Full-Stack Web Framework for Python

The table given below list out only some famous full-stack web framework for Python. Full-stack web framework means, framework used for both back-end as well as front-end development. Let's check it out:

Framework Developer License
Django Django Software Foundation BSD
Web2py Open-source software, Massimo di Pierro GNU LGPLv3
TurboGears Kevin Dangoor, Mark Ramm MIT, LGPL

Note - From above, Django is the most used web framework of Python to develop both small as well as large scale web applications.

Non Full-Stack Web Framework for Python

Now this time, the table given below list out two famous non full-stack web framework for Python. Non full-stack web framework are designed to build small size applications only.

Framework Developer License
Flask Armin Ronacher BSD
CherryPy Robert Brewer BSD

Note - From above, Flask is the most used web framework of Python to develop small scale web application.

Note - For graphic framework, use any of these two famous frameworks namely PyGame and Panda3d.

Python Programming Demo Codes

As all the essential details on Python programming are covered above, now let's see some codes written in Python. These codes are given to show you the demo of Python. You'll learn each and every thing in upcoming chapters.

print("Hey! Are you excited?")

produces exactly same output as shown in the snapshot given below:

python tutorial

Note - In next chapter, you will learn to Setup Environment for Python, that shows how a Python code can be written and executed.

Here is another code written in Python:

print("Enter First Name: ")
name = input()
print("\nHey", name, "\nAre you Ready?")

This program produces following output. This snapshot shows the initial output produced by above Python code:

learn python

Now enter your first name say James and press ENTER key to see the following output:

python programming

Note - I've written in-depth tutorial about Receiving Inputs from User in Python separately.

Note - To learn Python without reading theory, that is by reading the code and its output, then start with Python Programming Examples. There I've written almost thousands of codes in Python, that helps a lot. But I recommend you to first read the tutorial. Because tutorial provides all the essential details about the topic along with example code and its respective output.

Hot Topics of Python Programming

These are the list of some hot topics of Python programming language:

Message for Audience before Starting Python Tutorial

This tutorial of Python programming is designed for all those who eagerly wants to learn Python. Therefore, If you too are interested in Python, then follow the tutorial.

This tutorial is designed for all, that is for beginners, intermediate Python programmer, and for those who wants to expertise in the field.

Note - I've included as many codes as possible in each and every chapter, to provide you the best experience of learning in both theory as well as practical way. All codes are written along with its respective output wherever required.

Note - All the codes, I've written here, using PyCharm IDE.

Some Prerequisites for Learner

Python is good for beginner. Therefore, you can start learning Python here without having any prior knowledge.

The only prior knowledge is basic computer skills, that needs to setup the environment for Python as told in next chapter.

But if you've some basic commands on any programming language. Then trust me, your speed of learning Python increases based on how much command you've on programming. So let's begin. Best of luck!

Python Online Test

« Python Examples Next Tutorial »