PYTHON TUTORIAL || LEARN PYTHON || WHAT IS PYTHON || APPLICATION OF PYTHON || DATA SCIENCE AS PYTHON

PYTHON TUTORIAL :

Today, Python is one of the most popular programming languages. Although it is a general-purpose language, it is used in various areas of applications such as Machine Learning, Artificial Intelligence, web development, IoT, and more.

This Python tutorial has been written for the beginners to help them understand the basic to advanced concepts of Python Programming Language. After completing this tutorial, you will find yourself at a great level of expertise in Python, from where you can take yourself to the next levels to become a world class Software Engineer

What is Python?
Python is a very popular general-purpose interpreted, interactive, object-oriented, and high-level programming language. Python is dynamically-typed and garbage-collected programming language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source code is also available under the GNU General Public License (GPL).Python supports multiple programming paradigms, including Procedural, Object Oriented and Functional programming language. Python design philosophy emphasizes code readability with the use of significant indentation.This Python tutorial gives a complete understanding of Python programming language, starting from basic concepts to advanced concepts. This tutorial will take you through simple and practical approaches while learning Python Programming language.

First Programming: Python "Hello, World!"

To start with Python programming, the very basic program is to print "Hello, World!" You can use the print() function. Below is an example of Python code to print "Hello, World!" −

Python Online Compiler
Our Python programming tutorial provides various examples to explain different concepts. We have provided Online Python Compiler/Interpreter. You can Edit and Execute almost all the examples directly from your browser without the need to set up your development environment.

Try to click the icon run button to run the following Python code to print conventional "Hello, World!".

Charactertics of Python :
Following are important characteristics of Python Programming −

It supports functional and structured programming methods as well as OOP.
It can be used as a scripting language or can be compiled to byte-code for building large applications.
It provides very high-level dynamic data types and supports dynamic type checking.
It supports automatic garbage collection.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.


Applications of Python:
Python is a general purpose programming language known for its readability. It is widely applied in various fields.

In Data Science, Python libraries like Numpy, Pandas, and Matplotlib are used for data analysis and visualization.
Python frameworks like Django, and Pyramid, make the development and deployment of Web Applications easy.
This programming language also extends its applications to computer vision and image processing.
It is also favored in many tasks like Automation, Job Scheduling, GUI development, etc.

Features of Python:
The latest release of Python is 3.x. As mentioned before, Python is one of the most widely used languages on the web. I'm going to list a few of them here:

Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax. This allows the student to pick up the language quickly.
Easy-to-read − Python code is more clearly defined and visible to the eyes.
Easy-to-maintain − Python's source code is fairly easy-to-maintain.
A broad standard library − Python's bulk of the library is very portable and cross-platform compatible on UNIX, Windows, and Macintosh.
Interactive Mode − Python has support for an interactive mode that allows interactive testing and debugging of snippets of code.
Portable − Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
Extendable − You can add low-level modules to the Python interpreter. These modules enable programmers to add to or customize their tools to be more efficient.
Databases − Python provides interfaces to all major commercial databases.
GUI Programming − Python supports GUI applications that can be created and ported to many system calls, libraries, and Windows systems, such as Windows MFC, Macintosh, and the X Window system of Unix.
Scalable − Python provides a better structure and support for large programs than shell scripting.

Python Database Handling:
The following tutorials will help you learn how to work with different databases using Python programming:

Python MongoDB Tutorial
Python MySQL Tutorial
Python PostgreSQL Tutorial
Python SQLite Tutorial


Python Jobs:
Today, Python is very high in demand, and all the major companies are looking for great Python programmers to develop websites, software components, and applications or to work with data science, AI, and ML technologies. When we are developing this tutorial in 2022, there is a high shortage of Python programmers, where the market demands a greater number of Python programmers due to its applications in machine learning, artificial intelligence, etc.

Today, a Python programmer with 3-5 years of experience is asking for around $150,000 in an in an annual package, and this is the most demanding programming language in America. Though it can vary depending on the location of the job. It's impossible to list all of the companies using Python, to name a few big companies are:
Google
Intel
NASA
PayPal
Facebook
IBM
Amazon
Netflix
Pinterest
Uber
Many more...

Why to learn Python : 
Python is consistently rated as one of the world's most popular programming languages. Python is fairly easy to learn, so if you are starting to learn any programming language, then Python could be your great choice. Today, various schools, colleges, and universities are teaching Python as their primary programming language. There are many other good reasons that make Python the top choice of any programmer:

Python is open source, which means it's available free of cost.
Python is simple and so easy to learn.
Python is versatile and can be used to create many different things.
Python has powerful development libraries, including AI, ML, etc.
Python is much in demand and ensures a high salary.


Python is a MUST for students and working professionals to become great software engineers, especially when they are working in the web development domain. I will list down some of the key advantages of learning Python:

Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.
Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that encapsulates code within objects

Careers with Python:
If you know Python nicely, then you have a great career ahead. Here are just a few of the career options where Python is a key skill:

Game developer
Web designer
Python developer
Full-stack developer
Machine learning engineer
Data scientist
Data analyst
Data engineer
DevOps engineer
Software engineer
Many more other roles

Download Python
You can download Python from its official website: https://www.python.org/downloads/


Python Updates & New Features
The current stable version of Python is 3.13, which was released on October 7, 2024. Python 3.14 is still in the development phase with many new features and changes:

PEP 649: Deferred evaluation of annotations.
PEP 741: Python configuration C API.
PEP 761: Sigstore replaces PGP signatures for verification.
Improved error messages.

Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.

  • Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.

  • Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.

  • Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that encapsulates code within objects.

  • Python is a Beginner's Language − Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games.

Python's design philosophy is documented in the Zen of Python. It consists of nineteen aphorisms such as −

Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
Complex is better than complicated
To obtain the complete Zen of Python document, type import this in the Python Shell −


Pythonic Code Style
Python leaves you free to choose to program in an object-oriented, procedural, functional, aspect-oriented, or even logic-oriented way. These freedoms make Python a great language to write clean and beautiful code.

Pythonic Code Style is actually more of a design philosophy and suggests to write a code which is :

Clean
Simple
Beautiful
Explicit
Readable

History of Python
Python was developed by Guido van Rossum (a Dutch programmer) in the late 1980s and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands.

Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and other scripting languages. Guido van Rossum wanted Python to be a high-level language that was powerful yet readable and easy to use.

Python is copyrighted. Like Perl, Python source code is now available under the GNU General Public License (GPL).

For many uninitiated people, the word Python is related to a species of snake. Rossum though attributes the choice of the name Python to a popular comedy series Monty Python's Flying Circus on BBC.
Being the principal architect of Python, the developer community conferred upon him the title of Benevolent Dictator for Life (BDFL). However, in 2018, Rossum relinquished the title. Thereafter, the development and distribution of the reference implementation of Python is handled by a nonprofit organization Python Software Foundation.

Who Invented Python?
Python was invented by a Dutch Programmer Guido Van Rossum in the late 1980s. He began working on Python in December 1989 as a hobby project while working at the Centrum Wiskunde & Informatica (CWI) in the Netherlands. Python's first version (0.9.0) was released in 1991.

Evolution of Python The Major Python Versions

Following are the important stages in the history of Python −
Python 0.9.0
Python's first published version is 0.9. It was released in February 1991. It consisted of features such as classes with inheritance, exception handling, and core data types like lists and dictionaries..

Python 1.0
In January 1994, version 1.0 was released, armed with functional programming tools, features like support for complex numbers etc and module system which allows a better code organization and reuse.

Python 2.0
Next major version − Python 2.0 was launched in October 2000. Many new features such as list comprehension, garbage collection and Unicode support were included with it. Throughout the 2000s, Python 2.x became the dominant version, gaining traction in industries ranging from web development to scientific research. Various useful libraries like like NumPy, SciPy, and Django were also developed.

Python 3.0
Python 3.0, a completely revamped version of Python was released in December 2008. The primary objective of this revamp was to remove a lot of discrepancies that had crept in Python 2.x versions. Python 3 was backported to Python 2.6. It also included a utility named as python2to3 to facilitate automatic translation of Python 2 code to Python 3. Python 3 provided new syntax, unicode support and Improved integer division.

EOL for Python 2.x
Even after the release of Python 3, Python Software Foundation continued to support the Python 2 branch with incremental micro versions till 2019. However, it decided to discontinue the support by the end of year 2020, at which time Python 2.7.17 was the last version in the branch.

Current Version of Python
Meanwhile, more and more features have been incorporated into Python's 3.x branch. As of date, Python 3.11.2 is the current stable version, released in February 2023.

What's New in Python 3.11?
One of the most important features of Python's version 3.11 is the significant improvement in speed. According to Python's official documentation, this version is faster than the previous version (3.10) by up to 60%. It also states that the standard benchmark suite shows a 25% faster execution rate.

  • Python 3.11 has a better exception messaging. Instead of generating a long traceback on the occurrence of an exception, we now get the exact expression causing the error.

  • As per the recommendations of PEP 678, the add_note() method is added to the BaseException class. You can call this method inside the except clause and pass a custom error message.

  • It also adds the cbroot() function in the maths module. It returns the cube root of a given number.

  • A new module tomllib is added in the standard library. TOML (Tom's Obvious Minimal Language) can be parsed with tomlib module function.

Python in the Future

Python is evolving everyday where Python 3.x receiving regular updates. Python's developers community is focusing on performance improvements making it more efficient while retaining its ease of use.

Python is being heavily used for machine learning, AI, and data science, so for sure its future remains bright. It's role in these rapidly growing fields ensures that Python will stay relevant for years.

Python is also increasingly becoming the first programming language taught in schools and universities worldwide, solidifying its place in the tech landscape.


Python's most important features are as follows:

Easy to Learn

Dynamically Typed

Interpreter Based

Interactive

Multi-paradigm

Standard Library

Open Source and Cross Platform

GUI Applications

Database Connectivity

Extensible

Active Developer Community


Python Example

Take a look at the following simple Python program

a = int(input("Enter value for a")) b = int(input("Enter value for b")) print("The number you have entered for a is ", a) print("The number you have entered for b is ", b)

In our example, we have taken two variables "a" and "b" and assigning some value to those variables. Note that in Python, we don’t need to declare datatype for variables explicitly, as the PVM will assign datatype as per the user’s input.

The input() function is used to take input from the user through keyboard.

In Python, the return type of input() is string only, so we have to convert it explicitly to the type of data which we require. In our example, we have converted to int type explicitly through int( ) function.

print() is used to display the output. 

            

Hello World Program in Python

Printing "Hello World" is the first program in Python. This program will not take any user input, it will just print text on the output screen. It is used to test if the software needed to compile and run the program has been installed correctly.

Steps to install python

The following are the steps to write a Python program to print Hello World –


Step 1: Install Python. Make sure that Python is installed on your system or not. If Python is not installed, then install it from here: https://www.python.org/downloads/

Step 2: Choose Text Editor or IDE to write the code.

Step 3: Open Text Editor or IDE, create a new file, and write the code to print Hello World.

Step 4: Save the file with a file name and extension ".py".

Step 5: Compile/Run the program.


Python is a general-purpose programming language. It is suitable for the development of a wide range of software applications. Over the last few years Python has been the preferred language of choice for developers in the following application areas −

Data Science

Machine Learning

Web Development

Computer Vision and Image processing

Embedded Systems and IoT

Job Scheduling and Automation

Desktop GUI Applications

Console-based Applications

CAD Applications

Game Development

Data Science

Python's recent meteoric rise in the popularity charts is largely due to its Data science libraries. Python has become an essential skill for data scientists. Today, real time web applications, mobile applications and other devices generate huge amount of data. Python's data science libraries help companies generate business insights from this data.


Libraries like NumPy, Pandas, and Matplotlib are extensively used to apply mathematical algorithms to the data and generate visualizations. Commercial and community Python distributions like Anaconda and ActiveState bundle all the essential libraries required for data science.

Machine Learning

Python libraries such as Scikit-learn and TensorFlow help in building models for prediction of trends like customer satisfaction, projected values of stocks etc. based upon the past data. Machine learning applications include (but not restricted to) medical diagnosis, statistical arbitrage, basket analysis, sales prediction etc.


Web Development

Python's web frameworks facilitate rapid web application development. Django, Pyramid, Flask are very popular among the web developer community. etc. make it very easy to develop and deploy simple as well as complex web applications.


Latest versions of Python provide asynchronous programming support. Modern web frameworks leverage this feature to develop fast and high performance web apps and APIs.


Computer Vision and Image processing

OpenCV is a widely popular library for capturing and processing images. Image processing algorithms extract information from images, reconstruct image and video data. Computer Vision uses image processing for face detection and pattern recognition. OpenCV is a C++ library. Its Python port is extensively used because of its rapid development feature.


Some of the application areas of computer vision are robotics, industrial surveillance, automation, and biometrics etc.


Embedded Systems and IoT

Micropython (https://micropython.org/), a lightweight version especially for microcontrollers like Arduino. Many automation products, robotics, IoT, and kiosk applications are built around Arduino and programmed with Micropython. Raspberry Pi is also very popular alow cost single board computer used for these type of applications.

Job Scheduling and Automation

Python found one of its first applications in automating CRON (Command Run ON) jobs. Certain tasks like periodic data backups, can be written in Python scripts scheduled to be invoked automatically by operating system scheduler.


Many software products like Maya embed Python API for writing automation scripts (something similar to Excel micros).

Desktop GUI Applications

Python is a great option for building ergonomic, attractive, and user-friendly desktop GUI applications. Several graphics libraries, though built in C/C++, have been ported to Python. The popular Qt graphics toolkit is available as a PyQt package in Python. Similarly, WxWidgets has been ported to Python as WxPython. Python's built-in GUI package, TKinter is a Python interface to the Tk Graphics toolkit.


Console-based Applications

Python is often employed to build CLI (command-line interface) applications. Such scripts can be used to run scheduled CRON jobs such as taking database backups etc. There are many Python libraries that parse the command line arguments. The argparse library comes bundled with Pythons standard library. You can use Click (part of Flask framework) and Typer (included in FastAPI framework) to build console interfaces to the web-based applications built by the respective frameworks. Textual is a rapid development framework to build apps that run inside a terminal as well as browsers.


Game Development

Some popular gaming apps have been built with Python. Examples include BattleField2, The Sims 4, World of Tanks, Pirates of the Caribbean, and more. These apps are built with one of the following Python libraries.


Pygame is one of the most popular Python libraries used to build engaging computer games. Pygame is an open-source Python library for making multimedia applications like games built on top of the excellent SDL library. It is a cross-platform library, which means you can build a game that can run on any operating system platform.

Another library Kivy is also widely used to build desktop as well as mobile-based games. Kivy has a multi-touch interface. It is an open-source and cross-platform Python library for rapid development of game applications. Kivy runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi.

PyKyra library is based on both SDL (Software and Documentation Localisation) and the Kyra engine. It is one of the fastest game development frameworks. PyKyra supports MPEG , MP3, Ogg Vorbis, Wav, etc., multimedia formats.