0% found this document useful (0 votes)
9 views2 pages

PPS_Micro_Adi2

The document outlines the features of Object-Oriented Programming (OOP), including class and object definitions, encapsulation, inheritance, polymorphism, and abstraction. It also discusses programming paradigms such as monolithic, procedural, structured, and OOP, highlighting their characteristics and examples. Additionally, it covers functions, string operations, and packages in Python, emphasizing modular programming and code reusability.

Uploaded by

siloy22215
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)
9 views2 pages

PPS_Micro_Adi2

The document outlines the features of Object-Oriented Programming (OOP), including class and object definitions, encapsulation, inheritance, polymorphism, and abstraction. It also discusses programming paradigms such as monolithic, procedural, structured, and OOP, highlighting their characteristics and examples. Additionally, it covers functions, string operations, and packages in Python, emphasizing modular programming and code reusability.

Uploaded by

siloy22215
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/ 2

**Features Of OOP** Class Variable:- Defined inside the class but

1. Class outside any method, shared by all objects of the


 Blueprint/template for creating objects. class. Only one copy exists for the whole class.
 Contains attributes (variables) and methods Changes affect all instances. Used for properties
(functions). common to all objects. Accessed using
 Defined using the class keyword. ClassName.variable or self.variable.
 Example: class Car: Object (Instance) Variable:- Unique to each
2. Object object (instance), defined inside methods using
 Instance of a class (real-world entity). self. Each object has its own copy. Changes
 Can access class methods and attributes. affect only that particular object. Used for
 Multiple objects can be created from one class. properties specific to each object. Accessed using
 Example: my_car = Car() self.variable.
3. Encapsulation Programming Paradigms
 Binds data and functions into a single unit Monolithic Programming: Code written in a
(class). single, large block with no division into
 Protects data from unauthorized access. functions or modules. Hard to understand, test,
 Uses access specifiers (private, public, etc.). and maintain. All logic is tightly connected,
 Example: self.__salary (private variable) making it difficult to reuse or update parts.
4. Inheritance Suitable only for very small programs. Example:
 Allows a class to acquire properties of another Early assembly or BASIC code.
class. Procedural Programming: Program divided
 Promotes code reuse and readability. into functions or procedures, following a step-
 Parent class → Base; Child class → Derived. by-step approach. Uses variables, loops, and
 Example: class Dog(Animal): conditionals. Data and functions are separate,
5. Polymorphism making it easy to read and debug for
 Same function behaves differently based on small/medium apps but not suitable for
object. large/complex systems. Example: C, Pascal.
 Can be achieved through method Structured Programming: Subset of procedural
overriding/overloading. programming that uses sequence, selection (if-
 Improves flexibility and reusability. else), and loops while avoiding goto statements
 Example: speak() in Dog and Cat classes. to prevent jumpy code. Focuses on clean, logical
6. Abstraction flow and encourages modular design, making it
 Shows only essential details, hides internal logic. easy to test, debug, and maintain. Example:
 Achieved using abstract classes and methods. Structured C, ALGOL.
 Focuses on what an object does, not how. Object-Oriented Programming (OOP): Code
 Example: @abstractmethod def start(): organized using classes and objects, combining
**Class Method** data and behavior together. Follows principles:
 Belongs to the class, not instance (object). Encapsulation, Inheritance, Polymorphism,
 Uses @classmethod decorator. Abstraction. Promotes code reusability and
 First argument is cls (refers to the class). modularity, making it great for large, complex
 Can access/modify class variables. applications and more secure through data
 Can be called using class name or object. hiding. Example: Python, Java, C++.
 Useful for creating objects in different ways U6
(factory methods). File Access Modes: read(): r, r+, w+, a, a+;
 Does not use self (that’s for instance methods). readline(): r, r+, w+, a, a+; readlines(): r, r+,
Ex.class Student: w+, a, a+; write(): w, w+, a, a+, r+; writelines():
count = 0 w, w+, a, a+, r+; append(): a, a+.
def __init__(self, name): Dictionary Methods: dict(), Creating dict. by
self.name = name value, delete item, Adding Key Value.
Student.count += 1 Operations Of Dict: get(), keys(), update(),
@classmethod pop().
def show_count(cls): Directory:-
print("Total Students:", cls.count) mkdir(),getcwd(),rmdir(),chdir(),makedir()
U3 modular programming. Import modules using
Function: A block of reusable code that dot notation (e.g., import package.module).
performs a specific task, helps avoid repeating //from mypackage import module1
code, and makes programs clean and modular. //module1.my_function()
Can take inputs (parameters) and return outputs Modules in Python:- A module in Python is a
(using return). In Python, it starts with the def single .py file that contains functions, classes, or
keyword. variables. It helps to organize code into clean,
Need for Function: Avoids code repetition manageable, and reusable parts. Modules can be
(DRY principle), makes code organized and either built-in (like math, random) or user-
clean, easier to test and debug. Allows code defined. You can use them in your program by
reuse, breaks big problems into small parts, using the import keyword, and you can choose to
improves readability and teamwork, and supports import the entire module or specific items from it
modular programming. U4
How to Define a Function: Use the def String:A string is a sequence of characters
keyword, give a function name, add parentheses written in quotes ('Hello', "World"). Strings are
() (with/without parameters), end the line with a immutable, meaning once created, they can't be
colon :, write the function body with proper changed. You can use indexing (s[0]) and slicing
indentation, and optionally use return to send (s[1:4]) to access parts of a string. They're
back a result. commonly used to store and work with text
How to Call a Function: Use the function name, data. Example: name = "Aditya".
add parentheses (), pass required arguments (if Operations on String:You can concatenate
any), can call multiple times, and if the function strings using + ("Hi" + "There"), or repeat them
returns a value, store it using a variable. using * ("Ha" * 3 → "HaHaHa"). Use slicing
Required Arguments: Must be passed in correct (s[0:3]) to get parts of a string. The len() function
order, with the number of arguments matching returns the length of a string, and you can check
the function definition. Missing one will cause if a character is present using membership ('a' in
an error, and no default values are provided. "apple").
Keyword Arguments: Use name=value format String Methods:Python provides built-in string
while calling, order doesn't matter, improves methods like lower() (to lowercase), upper() (to
code clarity, and is useful with many arguments. uppercase), strip() (removes extra spaces),
Default Arguments: Has a default value in the replace(old, new) (replaces text), and split()
function definition, used when no value is (splits string into a list). zfill(width): Pads the
passed, saves from passing common values string with zeros on the left until the total length
repeatedly, and must be placed after required is width. reindex(): Not a string method in
arguments. Python — it's used in Pandas for DataFrames. If
Variable-Length Arguments: Accepts multiple you meant rindex(), it's not a valid method either;
values (any number), use *args for multiple use rfind() or index() instead. ljust(width): (Not
positional arguments, use **kwargs for multiple Ijust, correct method is ljust) — Pads the string
keyword arguments, and is useful when the with spaces on the right so the total length
number of inputs is unknown. becomes width. index(sub): Returns the
Lambda Function: A small anonymous function position of the first occurrence of sub in the
(no name), defined using the lambda keyword. string. Raises an error if not found. isdigit():
Can have any number of inputs but only one Returns True if all characters in the string are
expression, used for short, simple tasks, often digits, otherwise False
used with functions like map(), filter(), sorted(), Comparison Operations:Strings can be
and returns the value automatically (no return compared using == (equal), != (not equal), <, >,
keyword). Syntax: lambda arguments: <=, >=. These comparisons are alphabetical
expression.// add = lambda a, b: a + b// (lexicographical), so "apple" < "banana" is True.
print(add(2, 3)) # Output: 5 Also, comparisons are case-sensitive — "Apple"
Packages in Python - A package is a folder != "apple".
containing related Python modules (.py files) that  ord() returns the ASCII (or Unicode)
must include an __init__.py file (can be empty). number of a character.
Packages enable code organization, reuse, and  chr() returns the character corresponding

You might also like