0% found this document useful (0 votes)
11 views

Python.pptx

Python is an open-source, high-level, interpreted programming language widely used for web development, data science, machine learning, and automation. It offers advantages such as readable syntax and a strong community, but has limitations including slower performance and complex dependency management. Key programming concepts include variables, functions, object-oriented programming principles, and the use of libraries for various applications.

Uploaded by

mansi19042001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python.pptx

Python is an open-source, high-level, interpreted programming language widely used for web development, data science, machine learning, and automation. It offers advantages such as readable syntax and a strong community, but has limitations including slower performance and complex dependency management. Key programming concepts include variables, functions, object-oriented programming principles, and the use of libraries for various applications.

Uploaded by

mansi19042001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Python

high-level, interpreted programming language


What is Python?
Python is a
• open source,
• high-level,
• Interpreted,
• general-purpose,
• object oriented and
• very popular programming language
Applications
• Web Development: Building dynamic websites using frameworks like Django and Flask.
• Data Science and Machine Learning: Analyzing data and building machine learning
models with libraries like NumPy, pandas, scikit-learn, TensorFlow, and PyTorch.
• Scientific Computing: Performing numerical simulations, mathematical modeling, and
data visualization using libraries like SciPy and matplotlib.
• Artificial Intelligence and Natural Language Processing: Developing AI and NLP
applications with libraries like NLTK, spaCy, and Gensim.
• Automation and Scripting: Automating tasks, writing scripts, and developing system
administration tools..
Applications
• Game Development: Prototyping and scripting games using libraries like
Pygame and Panda3D.
• Web Scraping and Data Mining: Extracting data from websites, APIs, and
databases using tools like BeautifulSoup and Scrapy.
• Financial and Quantitative Analysis: Analyzing financial data, algorithmic
trading, and portfolio optimization using libraries like pandas and QuantLib.
• Desktop GUI Applications: Developing cross-platform desktop GUI
applications using libraries like Tkinter, PyQt, and wxPython
Advantages of Python:
• Readable and simple syntax
• Versatile for various applications
• Comprehensive standard library
• Vibrant ecosystem of third-party packages
• Interpretation and dynamic typing
• Cross-platform compatibility
• Strong community support
Limitations of Python:
• Slower performance compared to lower-level languages
• Higher resource consumption
• Complex packaging and dependency management
• Limited usage in mobile development
• Compatibility issues between Python 2 and 3
My First Program On Python
Comments
• Comments are used for the purpose of explaining Python code.
• They enhance code readability by providing explanations.
• Comments are effective in preventing code execution during testing phases.
Variables
Variables are containers for storing data values.
Variable names are case-sensitive.
Built-in Data Types
Setting Specific Data Type

If you want to specify the data


type, you can use the following
constructor functions:
Type Casting
You can get the data type of a variable with the type() function.
If you want to specify the data type of a variable, this can be done with casting.
Variable Names
Rules for Python variables:
1. A variable name must start with a letter or the underscore
character
2. A variable name cannot start with a number
3. A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
4. Variable names are case-sensitive (age, Age and AGE are three
different variables)
5. A variable name cannot be any of the Python keywords.
Assign Multiple Values
Python allows you to assign values to multiple variables in one line:
Concatenation
Slicing Strings
Specify the start index and the end index, separated by a colon, to return a part
of the string.
Modify Strings
If ... Else
Program to check relation between two no.

Loops
Python has two primitive loop commands:
● while loops
● for loops
Functions
In Python a function is defined using the def keyword:
Exception Handling
The try block will generate an exception, because x is not defined:
Questions
1. Write a program that takes radius of a circle as input, find and print
Area of a Circle.
2. Write a program that takes length and breath as input, find and print
Area of a rectangle.
3. Write a program that takes side as input, find and print Area of a sq.
Oops:Classes & Object
A class in programming is a blueprint or template for creating objects. It defines the
properties (attributes) and behaviors (methods) that objects of that class will have.
Essentially, a class serves as a model for creating instances of itself.
An object is an instance of a class. When you create an object from a class, you are
creating a specific instance that has its own unique attributes and can perform actions
based on the methods defined in the class.

A class is a blueprint that defines the properties and behaviors of objects.


An object is an instance of a class, representing a specific realization of that blueprint
with its own unique attributes and capabilities.
For example, consider a class Car:
In this class:

__init__() is a special method called


the constructor, used for initializing
object instances. It takes parameters
such as brand, model, and year.

display_info() is a method that prints


out information about the car.
Now, you can create objects (instances) of the
Car class:
Here, car1 and car2 are objects of the
Car class, each with its own set of
attributes (brand, model, year) and the
ability to perform actions defined in
the class (display_info() method).
Explanation:

Car Class:

Defines the blueprint for creating cars.


Attributes: brand, model, year.
Method: display_info() to print car information.

car1 and car2 Objects:

Instances of the Car class.


Have their own unique brand, model, and year attributes.
Can perform actions like displaying information using the display_info() method.
Pillars of Oops
The four pillars of OOP are:

Encapsulation: Bundling data and methods into a single unit (class) for data protection
and organization.

Abstraction: Hiding complex details and showing only essential features for easier use.

Inheritance: Allowing new classes to inherit attributes and methods from existing ones
for code reuse.

Polymorphism: Using the same method name in different classes to perform different
actions, enhancing flexibility.
Encapsulation
Encapsulation involves bundling data
(attributes) and methods (functions)
that operate on that data into a single
unit (class).

In this example, brand and model are


encapsulated within the Car class, and
display_info() is a method that
accesses and displays this
encapsulated data.
Abstraction
Abstraction focuses on hiding complex
implementation details and exposing only
essential features or interfaces.

Here, Shape is an abstract class with an


abstract method calculate_area(). Rectangle
is a concrete class that inherits from Shape
and implements calculate_area(),
demonstrating abstraction by defining an
essential method without specifying its
implementation in the abstract class.
Inheritance
Inheritance allows new classes (subclasses) to
inherit attributes and methods from existing
classes (superclasses).

In this example, Animal is the superclass, and


Dog is the subclass inheriting the speak()
method from Animal. The bark() method is
specific to Dog.
Polymorphism
Polymorphism allows objects of different
classes to be treated as objects of a common
superclass and enables methods in different
classes to have the same name but behave
differently.

Here, the move() function demonstrates


polymorphism by accepting objects of
different classes (Bird and Fish) and calling a
common method name (fly() for birds and
swim() for fish), showcasing different
behaviors based on the object type.
Libraries and Packages
Create 2D-3D Array

Code: Output:
Accessing elements
Code:

Output:
Basic operations: Sum, Mean, Transpose

Code:

Output:
Libraries and Packages
Create Series

Code: Output:
Create Series

Code: Output:
Customize Series

Code: Output:
Create DataFrame

Code: Output:
Accessing columns and rows

Code: Output:
Data filtering

Code: Output:

You might also like