0% found this document useful (0 votes)
3 views33 pages

Python Modules, Packages, and OOP Concepts

Uploaded by

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

Python Modules, Packages, and OOP Concepts

Uploaded by

M Narasimhareddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

MODULES AND PACKAGES AND

OOPS CONCEPT

Module 4
INTRODUCTION TO MODULES AND
PACKAGES

1. Modules in Python
✅ What is a Module?
• A module is a file containing
Python definitions and
functions.
• It allows you to organize your
code into separate files for
better readability and reuse.
INTRODUCTION TO MODULES AND
PACKAGES

1. Modules in Python
✅ What is a Module?
• A module is a file containing
Python definitions and
functions.
• It allows you to organize your
code into separate files for
better readability and reuse.
IMPORTING A MODULE
MODULE AND MEMBER ALIASING

🔹 Module and Member Aliasing in Python


Aliasing means giving a different name (an alias) to a module or
its member (function, class, etc.) when importing it. It helps
with:
• Shortening long module names
• Avoiding naming conflicts
• Improving code readability
MODULE AND MEMBER ALIASING
MODULE AND MEMBER ALIASING
MODULE AND MEMBER ALIASING
BUILT IN MODULES

Python includes a wide range of built-in modules that come


pre-installed with the standard library. Here are some of the most
1. sys
commonly used ones:
•Provides access to system-specific parameters and functions.
•Example: [Link] for command-line arguments, [Link]() to exit the
program.

2. os
•Interacts with the operating system, handles file paths, and directory
operations.
•Example: [Link](), [Link](), [Link]().

3. math
•Includes mathematical functions like sqrt(), pow(), factorial(), and
constants like pi and e.
BUILT IN MODULES

4. datetime
•Manages dates and times.
•Example: [Link]() returns the current date and time.

5. random
•Generates random numbers and performs random selections.
•Example: [Link](1, 10), [Link]([1, 2, 3]).

6. json
•Handles JSON serialization and deserialization.
•Example: [Link]() converts a dictionary to a JSON string, and
[Link]() does the reverse.
BUILT IN MODULES
7. re
•Supports regular expression operations.
•Example: [Link](r'\b\w+\b', 'Hello World!') extracts all words.

8. collections
•Implements specialized container data types like Counter, deque,
OrderedDict.
•Example: [Link](['a', 'b', 'a']) counts occurrences.

9. urllib
•Handles URL operations (e.g., opening URLs, parsing URLs).
•Example: [Link]('[Link]

10. itertools
•Provides iterator functions for efficient looping (e.g., count(), cycle(),
chain()).
•Example: [Link]([1, 2, 3], 2) generates all 2-
combinations.
USER DEFINED FUNCTION
USER DEFINED FUNCTION
USER DEFINED FUNCTION
USER DEFINED FUNCTION
ARGUMENTS IN PYTHON

• Arguments are values passed to a function when it is called. In


Python, there are four main types of arguments:
ARGUMENTS IN PYTHON
ARGUMENTS IN PYTHON
ARGUMENTS IN PYTHON
ARGUMENTS IN PYTHON
ARGUMENTS IN PYTHON
BASIC CONCEPTS OF OOPS

• Object-Oriented Programming (OOP) is a


programming paradigm that models real-world
entities as objects. These objects are instances
of classes, which define their properties
(attributes) and behaviors (methods).

1️⃣Classes and Objects


• Class: A blueprint for creating objects. Defines
attributes (properties) and methods (behaviors).
• Object: An instance of a class. Each object has
its own state and behavior.
BASIC CONCEPTS OF OOPS

2️⃣Encapsulation
• Bundling of data (attributes) and methods that operate on the
data within one unit (class).
• Restricts access to some components to prevent accidental
modification.
BASIC CONCEPTS OF OOPS

3️⃣Inheritance
• Allows a class to inherit attributes and methods from another
class (parent class).
• Promotes code reusability.
BASIC CONCEPTS OF OOPS

4️⃣Polymorphism
• Allows objects to be treated as instances of their parent class,
even if they are of different types.
• Methods can have the same name but behave differently.
BASIC CONCEPTS OF OOPS

5️⃣Abstraction
•Hides complex implementation details and only exposes the
necessary parts.
•Achieved using abstract classes and methods (with the help of
the abc module)
INIT

In Python, __init__ is a special method known as the constructor. It is


automatically called when you create an instance of a class.
Its main purpose is to initialize the object's attributes and set its initial
state.
INIT
METHODS

• In Python, methods are functions that are defined inside a


class and are used to perform operations on objects created
from that class. Methods have access to the object's data
(attributes) and can modify its state.
METHODS
SELF

In Python, self is a conventionally used parameter name that represents the


instance of the class inside its methods. It allows you to access and modify the
attributes and methods of the class instance.

Why is self Needed?


[Link] allows each object (instance) to keep its own state
(attributes).
[Link] differentiates between instance variables and local
variables.
[Link] enables the object to refer to itself, making it possible to
access its own attributes and methods.
method to access the name attribute of that specific Dog instance. Without self, the method wouldn't know which dog's name to print.

SELF

In this example, self refers to the


instance of the Dog class.
When my_dog calls
the bark method, self is automatically
passed as the first argument, allowing
the method to access
the name attribute of that
specific Dog instance. Without self, the
method wouldn't know which dog's
name to print.
ADVANCED OOPS CONCEPT

You might also like