Python_merged
Python_merged
Project Synopsis
on
Submitted By:
Tushar Sharma [21EGJCS158]
Vinay Kumar Jha[21EGJAD027]
Justin tirkey [21EGJCS060]
Your Name
1 Introduction 3
1.1 History of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Key Features of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
6 Conclusion 13
1
7 References 14
2
Chapter 1
Introduction
Python is a high-level, interpreted programming language known for its clear syntax and read-
ability. Developed by Guido van Rossum and first released in 1991, Python has gained immense
popularity across various domains. Its design philosophy emphasizes code readability, making
it accessible for beginners and efficient for experienced programmers. Python is used in web
development, data analysis, artificial intelligence, scientific computing, automation, and more.
• Dynamically Typed: Python does not require variable declaration; types are deter-
mined at runtime, which offers flexibility but requires careful handling.
• Community Support: Python has a vibrant community that contributes to its libraries,
documentation, and forums, making it easy to find help and resources.
3
Chapter 2
Python is employed in a myriad of applications due to its versatility. Here are some notable
use cases:
@app . route ( ’/ ’)
def home () :
return " Hello , ␣ World ! "
if __name__ == ’ __main__ ’:
app . run ( debug = True )
This simple Flask application creates a web server that responds with ”Hello, World!” when
accessed at the root URL. The ‘debug=True‘ option allows for real-time error checking during
development.
# Load a dataset
4
data = pd . read_csv ( ’ data . csv ’)
In this example, we load a CSV file into a DataFrame, display its statistical summary, and
filter the data based on a specific condition.
This script iterates through a directory and renames all ‘.txt‘ files by adding a prefix.
5
Chapter 3
This loop will print numbers from 0 to 4. Python’s ‘range()‘ function generates a sequence
of numbers.
6
3.3 Functions
Functions are reusable blocks of code that perform specific tasks.
The ‘greet‘ function takes a name as an argument and returns a greeting string.
7
Chapter 4
Object-Oriented Programming in
Python
Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes
to structure software in a way that enhances code reusability and maintainability. Python fully
supports OOP and allows for the creation of classes that can encapsulate data and functions.
4.1.1 1. Encapsulation
Encapsulation is the bundling of data and methods that operate on that data within a single
unit, or class. This principle restricts direct access to some of an object’s components and can
prevent the accidental modification of data.
In this example, the ‘BankAccount‘ class encapsulates the ‘balance‘ attribute, making it
private and accessible only through its methods.
8
4.1.3 2. Inheritance
Inheritance allows a class to inherit attributes and methods from another class. This promotes
code reuse and creates a hierarchical relationship between classes.
Here, the ‘Dog‘ and ‘Cat‘ classes inherit from the ‘Animal‘ class and override the ‘speak‘
method to provide specific behavior.
4.1.5 3. Polymorphism
Polymorphism allows methods to do different things based on the object it is acting upon, even
when they share the same name. This can be achieved through method overriding and method
overloading.
dog = Dog ()
cat = Cat ()
4.1.7 4. Abstraction
Abstraction is the principle of hiding complex implementation details and showing only the
essential features of an object.
9
Listing 4.4: Abstraction Example
from abc import ABC , abstractmethod
The ‘Shape‘ class is an abstract base class that defines a common interface for all shapes,
while the ‘Rectangle‘ class implements the ‘area‘ method.
10
Chapter 5
Python’s extensive libraries provide pre-built functionalities that streamline development across
various domains.
5.1 NumPy
NumPy is a powerful library for numerical computing, enabling array operations and mathe-
matical functions.
This code snippet demonstrates how to create a NumPy array and calculate its mean.
5.2 Pandas
Pandas is a library for data manipulation and analysis, providing data structures like DataFrames.
df = pd . DataFrame ( data )
11
Here, we create a DataFrame from a dictionary and print its contents.
5.3 Matplotlib
Matplotlib is a plotting library that provides a wide range of visualization options.
x = [1 , 2 , 3 , 4]
y = [10 , 20 , 25 , 30]
plt . plot (x , y )
plt . xlabel ( ’X - axis ’)
plt . ylabel ( ’Y - axis ’)
plt . title ( ’ Simple ␣ Plot ’)
plt . show ()
12
Chapter 6
Conclusion
Python’s versatility and ease of use make it a leading choice for developers across various fields.
Its extensive libraries, strong community support, and clear syntax allow for efficient problem-
solving and application development. As Python continues to evolve, it remains an essential
tool for anyone looking to enter the world of programming, data science, web development, or
automation.
13
Chapter 7
References
14