1. Explain Features Of OOPS?
1) Class:
A class is a user-defined data type. It consists of data members and member
functions, which can be accessed and used by creating an instance of that class. It
represents the set of properties or methods that are common to all objects of one
type. A class is like a blueprint for an object.
For Example: Consider the Class of Cars. There may be many cars with different
names and brands but all of them will share some common properties like all of
them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the class,
and wheels, speed limits, mileage are their properties.
2) Object:
It is a basic unit of Object-Oriented Programming and represents the real-life
entities. An Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instantiated (i.e. an object is created) memory is allocated.
An object has an identity, state, and behavior. Each object contains data and code
to manipulate the data. Objects can interact without having to know details of each
other’s data or code, it is sufficient to know the type of message accepted and type
of response returned by the objects.
For example “Dog” is a real-life Object, which has some characteristics like color,
Breed, Bark, Sleep, and Eats.
3) Data Abstraction:
Data abstraction is one of the most essential and important features of object-
oriented programming. Data abstraction refers to providing only essential
information about the data to the outside world, hiding the background details or
implementation. Consider a real-life example of a man driving a car. The man only
knows that pressing the accelerators will increase the speed of the car or applying
brakes will stop the car, but he does not know about how on pressing the
accelerator the speed is increasing, he does not know about the inner mechanism
of the car or the implementation of the accelerator, brakes, etc in the car. This is
what abstraction is.
4) Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit. It is the
mechanism that binds together code and the data it manipulates. In
Encapsulation, the variables or data of a class are hidden from any other class and
can be accessed only through any member function of their class in which they are
declared. As in encapsulation, the data in a class is hidden from other classes, so
it is also known as data-hiding.
Consider a real-life example of encapsulation, in a company, there are different
sections like the accounts section, finance section, sales section, etc. The finance
section handles all the financial transactions and keeps records of all the data
related to finance. Similarly, the sales section handles all the sales-related
activities and keeps records of all the sales. Now there may arise a situation when
for some reason an official from the finance section needs all the data about sales
in a particular month. In this case, he is not allowed to directly access the data of
the sales section. He will first have to contact some other officer in the sales
section and then request him to give the particular data. This is what
encapsulation is. Here the data of the sales section and the employees that can
manipulate them are wrapped under a single name “sales section”.
5) Inheritance:
Inheritance is an important pillar of OOP(Object-Oriented Programming). The
capability of a class to derive properties and characteristics from another class is
called Inheritance. When we write a class, we inherit properties from other
classes. So when we create a class, we do not need to write all the properties and
functions again and again, as these can be inherited from another class that
possesses it. Inheritance allows the user to reuse the code whenever possible and
reduce its redundancy. Inheritance in Object Oriented Programming
6) Polymorphism:
The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form.
For example, A person at the same time can have different characteristics. Like a
man at the same time is a father, a husband, an employee. So the same person
posses different behavior in different situations. This is called polymorphism.
Polymorphism in OOPs
7) Dynamic Binding:
In dynamic binding, the code to be executed in response to the function call is
decided at runtime. Dynamic binding means that the code associated with a given
procedure call is not known until the time of the call at run time. Dynamic Method
Binding One of the main advantages of inheritance is that some derived class D has
all the members of its base class B. Once D is not hiding any of the public members
of B, then an object of D can represent B in any context where a B could be used.
This feature is known as subtype polymorphism.
8) Message Passing:
It is a form of communication used in object-oriented programming as well as
parallel programming. Objects communicate with one another by sending and
receiving information to each other. A message for an object is a request for
execution of a procedure and therefore will invoke a function in the receiving
object that generates the desired results. Message passing involves specifying the
name of the object, the name of the function, and the information to be sent.
2. Difference Between Class & Objects?
3. Write OOPs Concepts in Python?
OOPs Concepts in Python :-
Object-Oriented Programming (OOP) is a programming paradigm based on the
concept of “objects”, which contain data (attributes) and methods (functions) that
operate on the data. Python supports OOP and makes it easy to model real-world
problems.
1. Class
- A class is a blueprint or template for creating objects.
- It defines attributes and methods.
Syntax:
Class Student:
Def __init__(self, name):
Self.name = name
2. Object
- An object is an instance of a class.
- Objects hold actual data and can use the class’s methods.
Example:
S1 = Student(“Karan”)
Print(s1.name)
3. Inheritance:- Inheritance allows a class to inherit properties and methods from
another class. Promotes code reusability.
• Types of Inheritance:
I. Single Inheritance: A child class inherits from a single parent class.
II. Multiple Inheritance: A child class inherits from more than one parent class.
III. Multilevel Inheritance: A child class inherits from a parent class, which in turn
inherits from another class.
IV. Hierarchical Inheritance: Multiple child classes inherit from a single parent
class.
V. Hybrid Inheritance: A combination of two or more types of inheritance.
Example:
Class Animal:
Def speak(self):
Print(“Animal speaks”)
Class Dog(Animal):
Def bark(self):
Print(“Dog barks”)
D = Dog()
d.speak()
d.bark()
4. Polymorphism
- Polymorphism means “many forms”.
- It allows functions or methods to behave differently based on the
object.
Example:
Class Bird:
Def sound(self):
Print(“Chirp”)
Class Cat:
Def sound(self):
Print(“Meow”)
Def make_sound(animal):
Animal.sound()
Make_sound(Bird())
Make_sound(Cat())
5. Encapsulation
- Encapsulation means hiding internal details and showing only necessary features.
- Done using private (__) or protected (_) variables.
Example:
Class Person:
Def __init__(self):
Self._age = 20 # protected
Self.__salary = 50000 # private
Def get_salary(self):
Return self.__salary
6. Abstraction
- Abstraction hides complex details and shows only the essentials.
- Achieved using abstract classes and methods via abc module.
Example:
From abc import ABC, abstractmethod
Class Shape(ABC):
@abstractmethod
Def area(self):
Pass
Class Circle(Shape):
Def area(self):
Print(“Area of Circle”)
C = Circle()
c.area()
4. Write a Major Version of Python?
1. The Birth of Python
Python 0.9.0 (1991)
Python’s journey began with version 0.9.0, released by Guido van Rossum in 1991. This
initial release included core features such as exception handling, functions, and the
core data types: list, dict, str, and others. It also introduced the module system,
allowing the organization of code into reusable libraries.
2. Early Versions and Growth
Python 1.0 (1994)
Python 1.0 marked the official public release, bringing in significant features such as:
• Lambda, Map, Filter, and Reduce: Functional programming constructs that allowed
concise and powerful data manipulation.
• Exception Handling: A structured way to handle errors and exceptions in code.
Python 1.5 (1997)
Version 1.5 introduced important updates, including:
• Standard Library Enhancements: Expansion of the standard library, making Python
more versatile.
• Unicode Support: Initial support for Unicode, facilitating internationalization.
3. Establishing a Strong Foundation
Python 2.0 (2000):-
Python 2.0 was a pivotal release that laid the groundwork for modern Python with:
• List Comprehensions: A syntactic construct for creating lists based on existing
lists.
• Garbage Collection: Automatic memory management to reclaim unused memory.
• Unicode Support: Full support for Unicode, enabling better handling of
international text.
Python 2.7 (2010):-
Python 2.7 was the final major release in the Python 2.x series, bringing several
features from Python 3.x to ease the transition:
• Ordered Dictionaries: Dictionaries that maintain the insertion order of keys.
• Set Literals: A more convenient way to define sets.
• Improved Syntax: Enhanced syntax features, including more robust error handling
and new string formatting methods.
4. The Shift to Python 3
Python 3.0 (2008):-
Python 3.0, also known as “Python 3000” or “Py3k,” was a revolutionary release
designed to fix inconsistencies and remove redundant constructs from Python 2.x:
• Print Function: print became a function, enhancing consistency and flexibility.
• New Syntax and Semantics: Changes to integer division, Unicode string handling,
and more.
• Removal of Deprecated Features: Simplification of the language by removing
outdated features.
Python 3.4 (2014):-
Version 3.4 introduced several significant enhancements:
• Asyncio: A framework for writing asynchronous programs, allowing for concurrent
code execution.
• Pathlib: An object-oriented filesystem paths library.
Python 3.5 (2015):-
Python 3.5 brought in important features for modern programming:
• Type Hints: A syntax for adding type annotations to function arguments and return
values.
• Async and Await: Syntactic support for asynchronous programming, making async
code more readable and maintainable.
5. Modern Python
Python 3.6 (2016):-
Python 3.6 was a landmark release with multiple enhancements:
• Formatted String Literals (f-strings): A concise and readable way to embed
expressions inside string literals.
• Underscores in Numeric Literals: Improved readability of large numbers.
• Asynchronous Generators: Enhancements to asynchronous programming.
Python 3.7 (2018):-
This version focused on performance and new features:
• Data Classes: A decorator for automatically generating special methods like
__init__ and __repr__ in classes.
• Context Variables: A way to manage context-local state.
Python 3.8 (2019):-
Python 3.8 introduced several new features and optimizations:
• Walrus Operator (:=): An assignment expression that allows assignment and return
of a value within an expression.
• Positional-only Parameters: A way to specify arguments that can only be passed
positionally.
Python 3.9 (2020):-
Python 3.9 continued to enhance the language:
• Dictionary Merge and Update Operators: New operators | and |= for merging and
updating dictionaries.
• String Methods: New methods like str.removeprefix() and str.removesuffix().
Python 3.10 (2021):-
Python 3.10 focused on usability and language consistency:
• Pattern Matching: A powerful feature for matching complex data structures.
• Parenthesized Context Managers: Support for multiple context managers in a
single with statement.
Python 3.11 (2022):-
Python 3.11 aimed at improving performance and developer experience:
• Performance Improvements: Significant speed improvements across various
operations.
• Error Messages: More informative and precise error messages.
Python 3.12 (2023):-
The future release of Python 3.12 bring more optimizations and features, continuing
the evolution of the language.
• Improved Error Messages in Python
• More Flexibility in Python F-String
• Type Parameter Syntax
• Improvement in Modules
• Syntactic Formalization of f-strings
Python 3.13 (2024):-
The future release of Python 3.12 is expected to bring more optimizations and
features, continuing the evolution of the language.
5. What is Python? List and explain feature of Python?
Python is a high-level, interpreted, general-purpose programming language known for
its simplicity and readability. It was created by Guido van Rossum and first released in
1991. Python supports multiple programming paradigms like procedural, object-
oriented, and functional programming.
• It is widely used in areas like:
- Web development
- Data Science
- Machine Learning
- Automation
- Software Development
- Game Development
• Features of Python:-
1. Simple and Easy to Learn
- Python syntax is clean and readable, similar to English.
- Beginners can easily learn and understand it.
Example:
Print(“Hello, World!”)
2. Interpreted Language
- Python code is executed line by line, which makes debugging easier.
- No need for compilation before execution.
3. High-Level Language
- You don’t need to manage memory or system-level operations.
- Focus remains on logic and functionality.
4. Cross-Platform (Portable)
- Python code runs on multiple platforms (Windows, Mac, Linux) without
modification.
5. Free and Open Source
- Python is freely available to download and use.
- The source code is open, allowing users to modify and distribute it.
6. Extensive Standard Library
- Comes with a rich set of built-in modules and functions (e.g., math, datetime,
random, os).
- Reduces the need to write code from scratch.
7. Object-Oriented Programming (OOP)
- Supports OOP concepts like classes, inheritance, encapsulation, and
polymorphism.
8. Dynamically Typed
- You don’t need to declare the data type of a variable.
- The type is determined at runtime.
Example:
X = 10 # integer
X = “Hello” # now x is a string
9. Extensible and Embeddable
- Can include C/C++ code in Python.
- Useful for improving performance in heavy tasks.
10. Large Community Support
- Python has a vast community of developers.
- Thousands of third-party libraries are available (e.g., NumPy, Pandas, Django).
6. How Python Works?
1. Source Code (.py)
The developer writes code in a .py file using Python syntax.
Example: hello.py
Print(“Hello, World!”)
2. Python Interpreter
The Python interpreter is the engine that executes the code.
It performs two main steps:
(a) Compilation to Bytecode :-
- Python first compiles the .py file into a bytecode (not machine code).
- Bytecode is a low-level, platform-independent representation.
- It is stored in .pyc files (inside __pycache__).
(b) Execution by Python Virtual Machine (PVM) :-
- The bytecode is sent to the Python Virtual Machine (PVM).
- PVM reads bytecode instructions and executes them.
- It handles memory management, garbage collection, and error checking.
GOD’S PLAN BABY !!!
There is a 1% chance, and sometimes that chance is good enough.