UNIT-1
UNIT-1
UNIT-1
UNIT-1
History and Origin of Python Language
• Python is a widely used general-purpose, high-level programming language. It was
initially designed by Guido van Rossum in 1991 and developed by Python
Software Foundation. It was mainly developed for emphasis on code readability,
and its syntax allows programmers to express concepts in fewer lines of code.
• Who invented Python?
• In the late 1980s, history was about to be written. It was that time when working on
Python started. Soon after that, Guido Van Rossum began doing its application-
based work in December of 1989 at Centrum Wiskunde & Informatica (CWI)
which is situated in the Netherlands. It was started as a hobby project because he
was looking for an interesting project to keep him occupied during Christmas.
• The programming language in which Python is said to have succeeded is ABC
Programming Language, which had interfacing with the Amoeba Operating
System and had the feature of exception handling. He had already helped create
ABC earlier in his career and had seen some issues with ABC but liked most of the
features. After that what he did was very clever. He had taken the syntax of ABC,
and some of its good features. It came with a lot of complaints too, so he fixed
those issues completely and created a good scripting language that had removed all
the flaws.
Features
• Easy to code and maintain
Many people call it developer-friendly because it is quite easy to learn. Furthermore, we can learn to write its
code very easily in a few hours or days. Moreover, this is possible because it has only a few keywords, a simple
structure, and a clearly defined syntax.
• Open source and free
It is an open-source language which means that anyone can download it, use it, and share it. Moreover, it is free
of cost.
• Object-oriented
It supports object-oriented programming language features. For example, the concept of object and classes,
encapsulation, inheritance, etc.
• Supports GUI programming
Python has support for creating various GUI applications. Furthermore, these applications can work in many
system software and libraries. Besides, it has modules like PyQt5, PyQt4, wxPython, or Tk through which we
can make graphical user interfaces. Among them, PyQt5 is the most popular for making graphical apps.
• Extensible in nature
It is extensible in nature which means that we can use python code in other languages. For example C, C++ also
can compile that code in C or C++.
• Portable and Platform independent
It is portable in nature. Moreover, we can run the python code in any environment like windows, Linux, mac, etc
without changing it. Besides, if we write the code in one OS and run it on the other it is totally valid.
• Integrated Language
We can easily integrate it with other languages such as C, C++, etc. Hence, it is an integrated language.
• Huge Standard Library
There are a very large number of libraries in python. These libraries contain predefined modules
and functions for certain tasks. Hence, it becomes easy fr the programmer to develop the code
since he does not have to do all the things by himself. Moreover, the library is portable and cross-
platform compatible.
• Interpreted Language
It uses an interpreter for converting the source code into machine code. This means that we
execute the python code line by line. Hence, it becomes easy to debug the error and solve it.
• Dynamically Typed
This means that we do not have to define the type of the variable. The interpreter decides it itself
at the run time. Hence, the name dynamically typed.
• Scalable
It provides good support for large programs.
• Some additional features besides these are as follows:
It supports both object-oriented and procedure-oriented programming structure.
We can use it as a scripting language for large applications.
It contains automatic garbage collection.
It performs dynamic type checking.
Case sensitive in nature.
Useful for developing web applications.
it uses indentation for program structuring. Unlike other languages that use braces for the
distinction of blocks.
Limitations
• Performance: Python is generally slower than compiled languages like C or C++ due to its
interpreted nature.
• Mobile Development: Python is not commonly used for mobile app development, which is
dominated by Swift (iOS) and Kotlin (Android).
• Memory Consumption: Python can consume more memory than other languages, making it
less suitable for memory-constrained environments.
• Global Interpreter Lock (GIL): The GIL allows only one thread to execute at a time in
CPython, which can limit performance in CPU-bound multithreaded applications.
• Dynamic Typing: While flexible, dynamic typing can lead to runtime errors that are hard to
debug and may affect performance.
• Limited Support for GUI Development: Python’s GUI frameworks (like Tkinter and PyQt)
are less robust compared to dedicated frameworks in other languages.
• Fewer Libraries for Certain Domains: While Python has extensive libraries, some
specialized domains (like game development) have less support compared to languages like
C# or C++.
• Not Ideal for Low-Level Programming: Python is not suitable for low-level programming
tasks, such as writing operating systems or device drivers.
• Weak in Mobile Computing: Less support and fewer libraries compared to languages
tailored for mobile development.
• Deployment Challenges: Packaging and distributing Python applications can be more
complex compared to statically linked languages.
Major Applications of Python,
• 1. Web Development
It is one of the most astonishing applications of Python. This is because Python comes up with a
wide range of frameworks like Django, Flask, Bottle, and a lot more that provide ease to
developers. Furthermore, Python has inbuilt libraries and tools which make the web development
process completely effortless. The use of Python for web development also offers:
• Amazing visualization
• Convenience in development
• Enhanced security
• Fast development process
• 2. Machine Learning and Artificial Intelligence
Machine Learning and Artificial Intelligence are the hottest subjects right now. Python along with
its inbuilt libraries and tools facilitate the development of AI and ML algorithms. Further, it offers
simple, concise, and readable code which makes it easier for developers to write complex
algorithms and provide a versatile flow. Some of the inbuilt libraries and tools that enhance AI and
ML processes are:
• Numpy for complex data analysis
• Keras for Machine learning
• SciPy for technical computing
• Seaborn for data visualization
• 3. Data Science
Data science involves data collection, data sorting, data analysis, and data visualization.
Python provides amazing functionality to tackle statistics and complex mathematical
calculations. The presence of in-built libraries provides convenience to data science
professionals. Some of the popular libraries that provide ease in the data science process are
TensorFlow, Pandas, and Socket Learning. These libraries provide an ecosystem for fine-
tuning data models, data preprocessing, and performing complex data analysis.
• 4. Game Development
With the rapidly growing gaming industry, Python has proved to be an exceptional option for
game development. Popular games like Pirates of the Caribbean, Bridge Commander, and
Battlefield 2 use Python programming for a wide range of functionalities and add-ons. The
presence of popular 2D and 3D gaming libraries like pygame, panda3D, and Cocos2D makes
the game development process completely effortless.
• 5. CAD Applications
CAD refers to computer-aided design; it is the process of creating 3D and 2D models
digitally. This application has replaced manual drift and is used by architects, product
designers, and construction managers to design products with extremely high
consistency. Python is embedded with amazing applications like Blender, FreeCAD,
open cascade, and a lot more to efficiently design products. These provide enhanced
features like technical drawing, dynamic system development, recordings, file export,
and import.
• 6. Desktop GUI
Python is an interactive programming language that helps developers to create
GUIs easily and efficiently. It has a huge list of inbuilt tools for Python usage
are PyQT, kivy, wxWidgets, and many other libraries like them to build a fully
functional GUI in an extremely secure and efficient manner.
• 7. Web Scraping Application
Web scraping is an automated process used to extract information from
websites in an easier and faster way. The information is used by researchers,
organizations, and analysts for a wide variety of tasks. Python has a wide
range of features that make it suitable for web scraping some of them are:
• A concise syntax enhances readability and saves you time.
• A wide range of libraries and tools like pandas, matplotlib, and Selenium
makes the web scraping process easy and efficient.
• Easy to use and understand
How to Install Python: A Step-by-Step Guide
•
• python --version
• If Python is installed, it will display the version number
(e.g., Python 3.9.1). If it's not installed, move on to the
next steps.
• Step 2: Download Python
• Visit the official Python website at python.org. You'll find the latest Python
version available for download.
• Step 3: Choose the Right Version
• Python has two major versions: Python 2 and Python 3. Python 2 is no
longer supported, so it's recommended to download Python 3. Choose the
latest version of Python 3, which is displayed prominently on the website.
• Step 4: Download the Installer
• Click on the download link to get the Python installer for your operating
system (Windows, macOS, or Linux). For Windows, you'll see two options:
32-bit and 64-bit. Choose the one that matches your system.
• Step 5: Run the Installer
• After downloading, locate the installer file and run it. Follow the
installation wizard's instructions. Be sure to check the box that says "Add
Python X.X to PATH" during installation (replace "X.X" with the version
number you downloaded). This is essential for easy command-line access.
• Step 6: Verify the Installation
• Once the installation is complete, open your
command prompt or terminal again and run:
• python --version
• You should see the installed Python version.
• Step 7: Install a Code Editor (Optional)
• While Python includes the IDLE development environment, many
developers prefer using code editors like Visual Studio Code, PyCharm, or
Jupyter Notebook for a more robust coding experience. Download and
install a code editor of your choice.
• Step 8: Write Your First Python Code
• Open your code editor and create a new Python file with the ".py"
extension. For example, "hello.py.“
• print("Hello, World!")
• Save the file and run it from your code editor. You'll see "Hello, World!"
printed to the console.
Setting Up Path and Environment Variables
Windows
• Windows
• Add Python to PATH Manually (if not done during installation):
– Right-click on This PC or My Computer and select Properties.
– Click on Advanced system settings.
– Click on Environment Variables.
– In the System variables section, find and select the Path variable, then
click Edit.
– Click New and add the path to your Python installation (e.g.,
C:\Python39, C:\Python39\Scripts).
– Click OK to close all dialog boxes.
• Running Python
• Open a Command Line Interface:
– Windows: Open Command Prompt or PowerShell.
– macOS/Linux: Open Terminal.
• Run Python:
– To start the Python interpreter, type:
– You should see a prompt indicating you are in the Python interactive
shell.
• Run a Python Script:
– Create a Python file (e.g., script.py) using a text editor: