You are on page 1of 7

Introduction to Python:

What is python?
 Python is a simple, general purpose, high level, and object-oriented programming
language.
 Python is an interpreted scripting language.
 Python is an easy-to-learn yet powerful and versatile scripting language, which makes
it attractive for Application Development.
 We don't need to use data types to declare variable because it is dynamically typed,
so we can write a=10 to assign an integer value in an integer variable.
 Python makes development and debugging fast because no compilation step is
included in Python development, and the edit-test-debug cycle is very fast.
 Python is a case-sensitive language, which means that uppercase and lowercase
letters are treated differently. For example, 'name' and 'Name' are two different
variables in Python.
 Python has many third-party libraries that can be used to make its functionality
easier. These libraries cover many domains, for example, web development, scientific
computing, data analysis, and more.
 In Python, comments can be added using the '#' symbol. Any text written after the '#'
symbol is considered a comment and is ignored by the interpreter. This trick is
useful for adding notes to the code or temporarily disabling a code block. It also
helps in understanding the code better by some other developers.
Features of Python:
Python provides many useful features which make it popular and valuable from the other
programming languages. It supports object-oriented programming, procedural programming
approaches and provides dynamic memory allocation. We have listed below a few essential
features.
Easy to Learn and Use
 Python is easy to learn as compared to other programming languages. Its syntax is
straightforward and much the same as the English language. There is no use of the
semicolon or curly-bracket, the indentation defines the code block. It is the
recommended programming language for beginners.

Expressive Language
 Python can perform complex tasks using a few lines of code. A simple example, the
hello world program you simply type print ("Hello World"). It will take only one
line to execute, while Java or C takes multiple lines.

Interpreted Language
 Python is an interpreted language; it means the Python program is executed one line at
a time. The advantage of being interpreted language, it makes debugging easy and
portable.
Cross-platform Language
 Python can run equally on different platforms such as Windows, Linux, UNIX, and
Macintosh, etc. So, we can say that Python is a portable language. It enables
programmers to develop the software for several competing platforms by writing a
program only once.

Free and Open Source


 Python is freely available for everyone. It is freely available on its official
website www.python.org. The open-source means, "Anyone can download its source
code without paying any penny."

Object-Oriented Language
 Python supports object-oriented language and concepts of classes and objects come
into existence. It supports inheritance, polymorphism, and encapsulation, etc. The
object-oriented procedure helps to programmer to write reusable code and develop
applications in less code.

Large Standard Library


 It provides a vast range of libraries for the various fields such as machine learning, web
developer, and also for the scripting. There are various machine learning libraries, such
as Tensor flow, Pandas, Numpy, Keras, and Pytorch, etc. Django, flask, pyramids are
the popular framework for Python web development.

GUI Programming Support


 Graphical User Interface is used for the developing Desktop application. PyQT5,
Tkinter, Kivy are the libraries which are used for developing the web application.

Embeddable
 The code of the other programming language can use in the Python source code.
We can use Python source code in another programming language as well. It can
embed other language into our code.

Dynamic Memory Allocation


 In Python, we don't need to specify the data-type of the variable. When we assign some
value to the variable, it automatically allocates the memory to the variable at run time.
Suppose we are assigned integer value 15 to x, then we don't need to write int x =
15. Just write x = 15.
Where is Python used?
 Data Science: Data Science is a vast field, and Python is an important language for this
field because of its simplicity, ease of use, and availability of powerful data analysis
and visualization libraries like NumPy, Pandas, and Matplotlib.
o Desktop Applications: PyQt and Tkinter are useful libraries that can be used in
GUI - Graphical User Interface-based Desktop Applications.
o Software Development: Python is considered one of the best software-making
languages. Python is easily compatible with both from Small Scale to Large Scale
software.
o Artificial Intelligence: AI is an emerging Technology, and Python is a perfect
language for artificial intelligence and machine learning because of the availability of
powerful libraries such as TensorFlow, Keras, and PyTorch.
o Web Applications: Python is commonly used in web development on the backend with
frameworks like Django and Flask and on the front end with tools like JavaScript
and HTML.
o 3D CAD Applications: Python can be used for 3D computer-aided design (CAD)
applications through libraries such as Blender.
o Machine Learning: Python is widely used for machine learning due to its simplicity,
ease of use, and availability of powerful machine learning libraries.
o Computer Vision or Image Processing Applications: Python can be used for
computer vision and image processing applications through powerful libraries such as
OpenCV and Scikit-image.
o Speech Recognition: Python can be used for speech recognition applications through
libraries such as SpeechRecognition and PyAudio.
o Scientific computing: Libraries like NumPy, SciPy, and Pandas provide advanced
numerical computing capabilities for tasks like data analysis, machine learning, and
more.
o Testing: Python is used for writing automated tests, providing frameworks like unit
tests and pytest that help write test cases and generate reports.
o Gaming: Python has libraries like Pygame, which provide a platform for developing
games using Python.
o IoT: Python is used in IoT for developing scripts and applications for devices like
Raspberry Pi, Arduino, and others.
o Networking: Python is used in networking for developing scripts and applications for
network automation, monitoring, and management.
o DevOps: Python is widely used in DevOps for automation and scripting of
infrastructure management, configuration management, and deployment processes.
Internal working of python:
Python doesn’t convert its code into machine code, something that hardware can understand.
It converts it into something called byte code. So within Python, compilation happens, but
it’s just not in a machine language. It is into byte code (.pyc or .pyo) and this byte code can’t
be understood by the CPU. So we need an interpreter called the Python virtual machine to
execute the byte codes.

How is Python Source Code Converted into Executable Code?


The Python source code goes through the following to generate an executable code
Step 1: The Python compiler reads a Python source code or instruction in the code editor. In
this first stage, the execution of the code starts.
Step 2: After writing Python code it is then saved as a .py file in our system. In this, there are
instructions written by a Python script for the system.
Step 3: In this the compilation stage comes in which source code is converted into a byte code.
Python compiler also checks the syntax error in this step and generates a .pyc file.
Step 4: Byte code that is .pyc file is then sent to the Python Virtual Machine (PVM) which is
the Python interpreter. PVM converts the Python byte code into machine-executable code and
in this interpreter reads and executes the given file line by line. If an error occurs during this
interpretation then the conversion is halted with an error message.
Step 5: Within the PVM the byte code is converted into machine code that is the binary
language consisting of 0’s and 1’s. This binary language is only understandable by the CPU of
the system as it is highly optimized for the machine code.
Step 6: In the last step, the final execution occurs where the CPU executes the machine code
and the final desired output will come as according to your program.
How Python Internally Works?
Code Editor: Code Editor is the first stage of programs where we write our source code. This
is human-readable code written according to Python’s syntax rules. It is where the execution
of the program starts first.
Source code: The code written by a programmer in the code editor is then saved as a .py file
in a system. This file of Python is written in human-readable language that contains the
instructions for the computer.
Compilation Stage: The compilation stage of Python is different from any other programming
language. Rather than compiling a source code directly into machine code. python compiles a
source code into a byte code. In the compilation stage python compiler also checks for syntax
errors. after checking all the syntax errors, if no such error is found then it generates a .pyc file
that contains bytecode.
Python Virtual Machine (PVM): The byte code then goes into the main part of the conversion
is the Python Virtual Machine (PVM). The PVM is the main runtime engine of Python. It is an
interpreter that reads and executes the byte code file, line by line. Here in the Python Virtual
Machine translate the byte code into machine code which is the binary language consisting of
0s and 1s. The machine code is highly optimized for the machine it is running on. This binary
language is only understandable by the CPU of a system.
Running Program: At last, the CPU executes the given machine code and the main outcome
of the program comes as performing task and computation you scripted at the beginning of the
stage in your code editor.
Python Libraries/Modules
When you import libraries or modules in your Python program. Firstly python checks if the
given module is built-in, and executes the corresponding C code. If the module is not built-in
then the list of directories is defined in sys. path. The directory of the input script, and
directories listed in the PYTHONPATH. If a .py file corresponds to the modules
imported, Python creates a new module object, on executing the code in the .py file within the
object’s namespace. Then Python compiles source code into byte code (the .pyc file), allowing
for quicker execution
How Compiler works:
How Interpreter Works:
Frozen Binaries:

 With the help of third party tools yours python programs into true executable, known
as Frozen Binaries in the python world.
 This programs can be run without requiring a python installation.
 Frozen binaries bundle together the byte code of your program files, along with the
PVM (interpreter) and any python support files your program needs, into a single
package.
 The end result can be a single binary executable program (e.g. an .exe file on
windows) that can easily be shipped to the customers.
 Today a variety of systems are capable of generating frozen binaries, which vary in
platforms and features.
 Py2exe for winnows only, but with broad windows support;
 PyInstaller, which is similar to py2exe but also works on Linux and Mac OS X.
 Py2app for creating Mac OS X applications.
 Freeze and cx_freeze, which offers both Python 3.X and cross –platform support.C vs.
Python programming language:
C Vs Python Language

C Language Python Language


1. C is procedural-oriented programming Python is an object oriented programming
language language.
2. In C, it is compulsory to declare the Data-type declaration is not required in
data-types of variables Python.
3. C has support for, while and do- Python has support for and while loops only.
while loops
4. C has support for switch statements Python does not support switch statements.
5. C does not allows Exception Python allows exception handling using try,
Handling catch-finally blocks.
6. The syntax of a C program is harder Syntax of python programs is easy to learn,
than python. write and read.
7. C has a limited number of built in Python has a large library of built in
functions. functions.
8. Pointers concept available in C No pointers concept are available.
language.
9. C programs are saved with .c Python programs are saved by .py extension.
extension.
10 It is mandatory to mark the end of It is not mandatory to mark the end of every
every statement with a semicolon in statement with a semicolon in Python.
C.

You might also like