0% found this document useful (0 votes)
10 views19 pages

UNIT 1 - Python

The document outlines problem-solving concepts and strategies, emphasizing the importance of understanding and defining problems before attempting to solve them. It introduces various problem-solving methods, including algorithmic and heuristic approaches, and details the six steps of problem-solving with computers. Additionally, it discusses programming paradigms, particularly focusing on Python programming and its features.

Uploaded by

vivek.rohidas
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)
10 views19 pages

UNIT 1 - Python

The document outlines problem-solving concepts and strategies, emphasizing the importance of understanding and defining problems before attempting to solve them. It introduces various problem-solving methods, including algorithmic and heuristic approaches, and details the six steps of problem-solving with computers. Additionally, it discusses programming paradigms, particularly focusing on Python programming and its features.

Uploaded by

vivek.rohidas
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

Unit I: Problem Solving, Programming and Python Programming

Content:
General Problem Solving Concepts- Problem-solving in everyday life, types of
problems, problem solving with computers, difficulties with problem solving, problem
solving aspects, top down design. Problem Solving Strategies, Basics of Python
Programming: Features of Python, History and Future of Python, Programming
Paradigm, Features of Object Oriented Programming, Applications of Python
Languages.

Problem:
A problem is a situation, condition, or issue that requires a solution. In other words,
a problem is something that causes difficulty or an obstacle to achieving a goal, completing
a task, or reaching a desired outcome
Characteristics of a Problem:

● Uncertainty: There's some form of unknown or unclear aspect that makes the
situation challenging.
● Obstacles: Problems often arise because something is blocking progress or making it
difficult to proceed.
● Need for a solution: A problem requires an answer, solution, or resolution to
overcome the challenge and restore balance or achieve a goal.

SIX STEPS OF PROBLEM SOLVING IN EVERYDAY LIFE


1. Identify the Problem

The first step in solving any problem is to clearly identify what the issue is. Without a clear
understanding of the problem, it's hard to find a solution.

Example: The computer is not starting when the power button is pressed.

2. Understand the problem and Gather Information

Once the problem is identified, gather relevant information that can help you solve it. This
could involve considering what resources you have, what’s within your control, and what
external factors are at play.

Example: Check possible reasons such as power supply, cables, or battery issues.

o Check if the power cable is connected.

o Check if there is electricity.

o Check if the battery is charged.


3. Identify the Possible Solutions

Think about different ways you can solve the problem. Often, there are multiple ways to
tackle an issue. Try to come up with a variety of options before deciding which one to use.

Example:

○ Plug the power cable properly.


○ Charge the battery.
○ Use another power socket.
○ Restart the computer.

4. Choose the Best Solution

After evaluating your options, choose the solution that seems most practical and effective for
the situation.

Example: Plug the power cable properly and try a different socket.

5. Take Action or follow instructions

Now it’s time to put your chosen solution into action. Make sure to follow step-by-step
instructions and address the problem directly.

Example:

o Connect the power cable correctly, switch to another socket, and turn ON the
computer.

6. Evaluate the Solutions

This step involves checking whether the chosen solution has successfully solved the problem
or not. After implementing the solution, the results are observed carefully to see if the
problem still exists or has been resolved. If the solution works, it confirms that the correct
approach was selected. If the problem remains, the process may need to be repeated by
choosing an alternative solution. This step helps in learning from the outcome and improving
future problem-solving efforts.

Example:

o Switch ON the computer after connecting the power cable properly.

o Observe whether the computer starts working or not.

o If the computer turns ON, the problem was due to a loose power cable.

o This confirms that the selected solution was correct and effective.

o If the computer does not turn ON, another cause must be checked and a new
solution applied.
Types of Problems

1. Problems based on algorithmic solution

2. Problem based on heuristic solution

1. Problems based on algorithmic solution :

Definition: Algorithmic problems are those that can be solved using a set of step-by-
step procedures or rules, known as algorithms.

The solution is deterministic, meaning if you follow the algorithm correctly, you'll
always get the correct answer. These problems typically have well-defined inputs and
outputs, and the algorithm leads to the correct solution every time.

Characteristics:

● Clear instructions: The problem-solving process is based on following a specific set


of steps or rules.
● Deterministic: For a given problem and set of inputs, the algorithm will always
produce the same output.
● Guaranteed result: As long as the algorithm is correct, it will give the right answer.

2. Problem based on heuristic solution :

Definition: Heuristic problems are those that are not solve by following step by step
instructions. Such problems solve by rules of thumb, educated guesses, or trial-and-error
methods, rather than following a strict set of instructions.

Heuristics are used when an exact solution is difficult or impossible to compute within a
reasonable amount of time. Heuristic methods are not guaranteed to provide the best solution.
Characteristics:

● Approximate solutions: The solution may not be optimal, but it's usually close
enough.
● No guarantee of the best result: Heuristic solutions might miss the best answer, but
they still provide a reasonable solution.

Example of Heuristic Problem:

● Problem: You’re trying to solve a puzzle where you have to arrange pieces to form a
picture, but there are many possible combinations of pieces.
● Heuristic: “Start by looking for corner pieces or pieces with unique shapes.” This
heuristic doesn’t guarantee you’ll complete the puzzle, but it helps you make progress
quickly without checking every possible piece.
Difficulties with problem-solving

1. Not understand problem correctly


2. Lack of problem-solving experience
3. List of alternatives is incomplete or unknowingly.
4. The sequence of solution to the problem is not logical many times.
5. Incorrect solution evaluation
6. Unable to take decisions while solving problems.
7. Alternative selection may be wrong.
8. Difficult to writing solution instruction
9. Invalid logic

Problem Solving with computer

The six steps of problem solving with a computer are:

1. Define the problem,

2. Analyze the problem,

3. Design the solution (algorithm),

4. Implement the solution (coding),

5. Test and debug,

6. Evaluate the results

1. Identify and Define the problem:


Clearly identify the issue you want to solve with the computer program, including its inputs,
expected outputs, and any constraints

2. Analyze the problem:


Break down the problem into smaller components and understand the relationships between
them, potentially using flowcharts or pseudocode to visualize the process.

3. Design the solution (algorithm):


Develop a step-by-step plan (algorithm) to solve the problem, including the logic and data
structures needed.

4. Implement the solution (coding):


Write the code in a programming language, translating the algorithm into executable
instructions.

5. Test and debug:


Run the code with different input scenarios to identify and fix any errors or unexpected
behavior.

6. Evaluate the results:


Assess whether the solution meets the original problem requirements, considering its
efficiency and functionality
Top-Down Design Model

In the top-down model, we first look at the system as a whole without going into details. Then,
we slowly break it into smaller parts and explain each part in more detail. This process
continues until every part is clearly defined and the full system is properly understood.

When we look at a big system all at once, it may seem impossible to build because it is very
complex. But we can solve complicated problems by using a method called stepwise
refinement.

Features of Top-Down Approach:

1. The big problem is divided into smaller and simpler parts.


2. It is commonly used in structured programming languages like C.
3. It focuses on proper documentation of modules and debugging of code.
4. Modules work independently and usually do not require much communication with
each other.
5. It may contain some repeated (redundant) information.
6. It uses a decomposition approach (breaking the problem into parts).
7. The implementation depends on the programming language and the platform used.
Problem-solving aspects

1. Problem definition phase

 Problem solving success depends on the understanding of the problem. It is


necessary to understand what we are trying to solve.
 This preliminary investigation of the problem is the problem definition phase.
 In this phase one should do 'what must be done' rather than 'how to do it'.

2. Getting started on a problem/Problem solution phase:

 There are many ways and solutions for many problems.


 Out of these many solutions it is the very difficult to find out the path which is correct
and productive.
 Even after the problem definition phase people don't have any idea where to start on the
problem.
 A block often occurs at this point because people become concerned with details of the
implementation before they have completely understood or worked out an
implementation independent solution.

3. The use of specific examples

 To start on a problem is to pick a specific example of the general problem we wish to


solve and try to work out the mechanism that will allow us to solve this particular
problem.
 When a problem looks difficult, it is better not to think about the whole problem at
once. Instead, choose one simple and small example related to the problem.
 By solving that one example step by step, we can understand the pattern or method
needed to solve it. This makes the problem less confusing and easier to handle.

4. Similarities among problems

 Like specific example, one can bring the past experience as possible to bear on the
current problem.
 One can see if there are any similarities between the current problem and the other
problems that we have solved or we have been solved.
 Past experience helps a lot in problem solving. If a new problem is similar to an
old one, we can use the same idea or method. Experience gives us confidence and
better techniques. 

5. Working backwards from the solution

 We can use the solution which is already available and try to work backward to
the starting conditions.
 if we do not know how to start, we can think about the final result and work
backwards. This method helps us understand what steps are needed to reach the
solution. Even guessing a possible answer can help us begin.
Problem Solving Strategies

Problem-solving strategies are systematic approaches or methods used to find solutions to


various types of problems. These strategies are helpful because they give structure to the
problem-solving process, ensuring that all aspects of the problem are addressed effectively.
Below are some common problem-solving strategies used in different situations:

1. Trial and Error :

Is a problem-solving strategy where you try different solutions or approaches to a problem


until you find one that works. It’s a very practical method, especially when the solution isn't
clear from the beginning or when other more systematic strategies aren't available.

Steps in Trial and Error:

1. Make a guess or hypothesis.


2. Test the solution.
3. Evaluate the result to see if it solved the problem.
4. If it works, you stop.
5. If it doesn’t work, you try another approach or solution.
6. Repeat this process until the correct solution is found.

2. Divide and Conquer :

This strategy involves breaking a large or complex problem into smaller, more manageable
parts. Once each part is solved, you can combine the solutions to tackle the entire problem.

When to use it: It's especially useful for large or complex problems where you can't find
an immediate solution. It makes tackling the issue step by step easier and more organized.

How it works:

1. Divide the problem into smaller, simpler sub-problems.


2. Solve each sub-problem individually.
3. Combine the solutions of each part to solve the original problem.

3. Brainstorming :

Brainstorming is a creative problem-solving method that encourages the generation of a wide


range of ideas or solutions without judgment. It’s meant to promote free thinking and explore as
many solutions as possible.

1. When to use it: Brainstorming is helpful when you need fresh ideas, want to generate
various options, or are dealing with creative or open-ended problems.

2. How it works:
• Gather a group of people (or do it solo) and write down all the ideas that come
to mind, no matter how far-fetched.
• Encourage everyone to contribute, and avoid critiquing ideas during this stage.
• After gathering a variety of ideas, evaluate and select the best ones.

3. Example: Coming up with marketing ideas for a new product, like social media
campaigns, partnerships, events, or influencer promotions.
4. Root Cause Analysis (RCA) :

What it is: Root Cause Analysis is a problem-solving method that focuses on identifying the
root cause of a problem rather than just addressing the symptoms. It’s used to prevent the
problem from recurring by solving the underlying issue.

1. When to use it: Root Cause Analysis is useful when you are dealing with recurring
issues or persistent problems, especially in environments where long-term solutions
are needed (like business operations, manufacturing, or software development).
2. How it works:
• Define the problem: Identify the problem and its symptoms.
• Identify possible causes: Gather data to find the factors that may be
contributing to the issue.
• Ask “why” repeatedly: Use the “5 Whys” technique to dig deeper into each
cause and trace back to the root cause.
• Fix the root cause: Address the underlying issue to prevent future
occurrences.
3. Example: If there’s a recurring delay in delivery at a company, RCA might reveal that
the root cause is poor communication between teams, rather than just a lack of staff or
resources.

5. A Decision Matrix (also known as a Priority Matrix or Weighted Decision Matrix) :


Is a tool used to evaluate and prioritize a list of options or solutions based on multiple criteria.
It helps you make a decision by comparing each option against the criteria that matter most.
When to use a Decision Matrix:

1. When you have multiple options to choose from and need to evaluate them based on
several important factors.
2. When you need to make a decision that involves subjective judgments or competing
priorities.
3. When you want to make an objective, data-driven choice among several alternatives.

Basics of Python
Programming Paradigms: A programming paradigm is an approach to solve the problem
using some programming language or also we can say it is a method to solve a problem using
tools and techniques that are available to us following some approach. There are lots of
programming languages that are known but all of them need to follow some strategy when
they are implemented and this methodology/strategy is paradigms

1. Monolithic Programming Approach:

The monolithic programming paradigm is characterized by writing entire programs as


a single block of code . In a monolithic application, everything is integrated together
and deployed as a single unit.

Characteristics of Monolithic Programming

 Single Block Structure: In monolithic programming, the entire program is written in


a single block without dividing it into smaller functions or modules. This means all co
de is contained within one main function, making it less organized.
 Global Data Usage: This paradigm typically uses global data, which can lead to data
insecurity and makes it difficult to manage state across different parts of the program
 Lack of Control Structures: Monolithic programming often lacks modern control str
uctures like loops and conditionals, relying instead on simple jumps (e.g., using goto s
tatements) to navigate through the code

Ex: Assembly Language

Advantages

 Simplicity: For small programs, monolithic programming can be straightforward and


quick to implement, as everything is in one place.

Disadvantages

 Difficult Maintenance: As programs grow larger, maintaining and debugging monolit


hic code becomes increasingly challenging. The lack of modularity makes it hard to is
olate issues.
 Code Reusability Issues: Since the code is not organized into reusable functions or m
odules, redundancy is common, leading to longer development times and increased pot
ential for errors

2. Procedural Programming Approach:

In this type of programming where the program is structured into procedures (also
known as routines, or subroutines). Procedures are a way to break down tasks into
smaller, manageable chunks of code, which can be reused.
Ex. C, COBOL,Pascal,Fortran
Key Characteristics

1. Step-by-step execution – Code runs in a defined sequence.


2. Procedures/Functions – Code is organized into reusable blocks.
3. Global and Local Variables – Data can be shared or isolated between functions.
4. Top-down approach – Start from the main problem, break it into smaller tasks.

Advantages

 Simplicity – Easy to understand and implement.

 Code Reusability – Functions can be reused in different parts of the program.

 Modularity – Breaking code into functions improves maintainability.

 Efficient for small to medium programs.

Disadvantages

 Poor scalability – Large projects become harder to manage.

 Data security issues – Global variables can be modified anywhere.

 Less flexible – Not ideal for complex, real-world modeling compared to OOP.

Examples of Procedural Languages: C,pascal,Fortran

3. Structured Programming Approach:

The Structured Programming Paradigm is a programming approach that emphasizes


writing clear, logical, and well-organized code using a top-down design and well-defined
control structures
Structured programming is based on:

1. Sequence – Instructions are executed one after another in a defined order.


2. Selection – Decision-making using control structures like if-else or switch.
3. Iteration – Repeating tasks using loops like for, while, or do-while.
4. Modularity – Breaking programs into smaller, reusable functions or procedure.
Key Characteristics:
 Introduces constructs like loops, conditionals (if-else), and subroutines
(functions) to control program flow in a structured and predictable way.
 Emphasizes readability, maintainability, and avoiding the use of unstructured
control flow (like jumps or "goto").
Ex: C, Ada, Modula-2.

Advantages

 Readability – Code is easier to understand.


 Maintainability – Easier to modify and update.
 Reusability – Functions can be reused in other programs.
 Reduced complexity – Breaking problems into smaller parts makes them easier to
solve.

Disadvantages

 May require more planning before coding.


 Can be less flexible for certain low-level operations.
 Not ideal for problems that are naturally event-driven or object-oriented

4. Object-Oriented Programming (OOP) Approach:

Object-oriented programming is often seen as an extension of imperative programming. In


OOP, the focus is on organizing code around objects, which are instances of classes
containing both data (attributes) and functions (methods) that operate on the data.

Key Characteristics:
1. Abstraction, Encapsulation, inheritance, and polymorphism.
2. Objects and methods allow for better abstraction and code organization.
3. Program flow is controlled by procedures and statements
Ex: Java, C++, Python (can support multiple paradigms)

Advantages :

 Reusability: Classes and objects can be reused across different programs, reducing
redundancy.
 Maintainability: Encapsulation and abstraction make the code easier to maintain and
debug.
 Scalability: The modular nature of OOP makes it easier to scale and extend
applications.
 Security: Encapsulation protects sensitive data from unauthorized access.
 Modularity
o Programs are divided into small parts called object.
o Makes the program easy to manage and understand.
 Easy Maintenance
 Errors can be fixed easily.
 Changes can be made without affecting the whole program.
History of Python:

● Guido van Rossum started working on Python during the Christmas holidays of 1989
at Centrum Wiskunde & Informatica (CWI) in the Netherlands. He wanted to create a
language that was easy to read, with a syntax that emphasized code readability.
● Python was intended as an improved version of the ABC programming language,
which was also developed at CWI but had some limitations. It combined elements
from languages like C, Modula-3, and ABC, with an emphasis on simplicity.
● Python 1.0 (1991): The first official version of Python was released.
● Python 2.0 (2000): Python 2 introduced key features like garbage collection and list
comprehensions. It became widely used.
● Python 3.0 (2008): Introduced backward-incompatible changes, aiming for cleaner
and more consistent code (e.g., print became a function).
● End of Python 2 (2020): Python 2 reached its end-of-life, and users were encouraged
to switch to Python 3.

Features of Python :
Python is a high-level, interpreted programming language known for its simplicity and
readability. It’s widely used for web development, data analysis, automation, artificial
intelligence, and more. Python is known for its simplicity and readability, but it also comes
with many powerful features that make it versatile and popular among developers.

1. Simple and Easy to Learn


Python has a simple syntax that is easy to read and understand, making it suitable for
beginners.

2. Interpreted Language
Python is processed at runtime by interpreter. So, there is no need to compile a
program before executing it
Python code is executed line by line, which makes debugging easier.
.
3. High-Level Language
Python handles memory management automatically, so programmers do not need to
worry about low-level details.

4. Object-Oriented Language
Python supports object-oriented concepts such as classes and objects.

5. Portable
Python programs can run on different platforms like Windows, Linux, and macOS
without modification.

6. Dynamically Typed
Variables do not need to be declared with a data type; Python assigns it automatically
at runtime.
For example:
x = 10 # Integer
x = 5.0 #float

x = "Hello" # Now a String


7. Large Standard Library
Python provides a rich set of built-in libraries for tasks like file handling, web
development, and data analysis.

8. Open Source
Python is free to use and its source code is available to everyone.

9. Garbage Collection: Python has automatic memory management through garbage


collection. It automatically handles the allocation and deallocation of memory, freeing
developers from manual memory management tasks

10. Scripting and Automation: Python is commonly used for writing scripts to
automate repetitive tasks, manage files, or interact with APIs. Its simple
syntax and the power of libraries make it an excellent choice for scripting.

11. Large Community Support: Python has a large and active community that provides
a wealth of tutorials, documentation, third-party libraries, and forums for help. This
community-driven approach has contributed significantly to Python’s growth and
popularity.

12. Scalability: Python support modular programming, so programmer


can add module at any stage of the program

13. Secure: Python programming environment is secure from


tempering

14. Readable and Maintainable Code : Python emphasizes readability


and simplicity, which makes it easier to maintain and debug code. Its
use of indentation instead of braces for code blocks improves the
readability of the code.

15. Community Support : Python has a large and active community


that provides a wealth of tutorials, documentation, third-party
libraries, and forums for help. This community-driven approach has
contributed significantly to Python’s growth and popularity.

Future of Python:

1. Continued Popularity: Python will remain popular, especially in fields like data
science, AI, web development, and automation.
2. Performance Improvements: Projects like PyPy and GraalPython aim to enhance
Python's performance.
3. lMachine Learning & AI: Python will continue to be a top language for machine
learning and artificial intelligence due to its libraries like TensorFlow, PyTorch, and
Scikit-learn.
4. Cloud & Web Development: Python will remain essential for cloud computing and
web frameworks like Django and Flask, with growing support for asynchronous
programming.
5. Community Growth: The Python community will keep growing, creating more tools
and libraries, keeping Python modern and adaptable.
APPLICATIONS OF PYTHON LANGUAGE

1. Web Development

● Python is widely used in web development


● Python allows you to quickly develop web applications, handle databases, and
manage web servers.

2. Data Science and Data Analysis

● Python is one of the most popular languages for data science due to libraries like:
o Pandas: Data manipulation and analysis.
o NumPy: Numerical computations.
● .It’s used for cleaning, analyzing, and visualizing large datasets to uncover trends
and insights.
● Python is the go-to language for working with big data and data analysis pipelines.

3. Machine Learning and Artificial Intelligence (AI)

● Python is the most widely used language in machine learning and AI .


● Python is used to build models for image recognition, natural language processing
(NLP), recommendation systems, and predictive analysis.

4. Automation and Scripting

● Python is often used for automating repetitive tasks such as:


o File management, renaming files, web scraping.
o Automating the setup of software, testing, or deployment pipelines.
● You can write Python scripts to automate almost anything, saving time and reducing
human error.

5. Game Development

● Python is used for developing games, especially simple ones or game prototypes.
● Libraries like Pygame make it easy to create 2D games and interactive applications.
● Although Python may not be the most popular language for high-performance 3D
games, it’s great for educational games or small projects.

6. Software Development

● Python is often used in software development for both backend logic and front-end
GUI applications:
● Python can be used for both rapid prototyping and building full-fledged software
applications.

7. Cybersecurity

● Python is extensively used in cybersecurity for:


o Writing penetration testing scripts.
o Building security tools for scanning networks, detecting vulnerabilities, or
brute-forcing passwords.
8. Networking

● Python is used to create and manage network applications:


o Socket programming allows for low-level networking operations.
o Python can be used to develop network servers, clients, and various network
protocols.
o It’s also used for building network monitoring tools and managing cloud
infrastructure.

9. Scientific Computing

● Python is widely used in scientific research and engineering due to its ease of use
and extensive libraries:
● It’s used in fields like physics, biology, chemistry, and engineering for simulations,
modeling, and data analysis.

10. Cloud Computing and DevOps

● Python is commonly used in cloud computing and DevOps for:


o Writing scripts for server management, deployment, and automation.
o Interacting with cloud platforms like AWS (Amazon Web Services), Google
Cloud, and Azure.
o Automating tasks, monitoring infrastructure, and scaling applications.

11. Natural Language Processing (NLP)

● Python is a go-to language for text processing and natural language understanding.
● Python is widely used in chatbots, speech recognition, and language translation
tools.

12. Education

● Python is commonly used as a first programming language in schools and universities


due to its simplicity and readability.
● It is also a popular language for learning algorithmic thinking, problem-solving,
and computer science fundamentals.

13. Finance and Trading

● Python is heavily used in the finance industry, particularly in quantitative finance


and algorithmic trading
● Libraries like Pandas and NumPy help with data manipulation and analysis.
Introduction of Object Oriented Programming
As the name suggests, Object-Oriented Programming or OOPs refers to languages that use
objects in programming. Object-oriented programming aims to implement real-world entities
like inheritance, hiding, polymorphism, etc in programming. The main aim of OOP is to bind
together the data and the functions that operate on them so that no other part of the code can
access this data except that function.

OOPs Concepts:

 Class

 Objects

 Data Abstraction

 Encapsulation

 Inheritance

 Polymorphism

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. A class is a blueprint or template used to
create objects.
● It defines the properties (variables) and behaviors (methods) of an object
o A class groups data and functions together.
o It is used to create multiple objects.
o It defines the structure of 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.
● Created from a class.
● Contains data and methods defined in the class.
● Used to access class properties and functions.
● Many objects can be created from one class.
● For example “Dog” is a real-life Object, which has some characteristics like color,
Breed, Bark 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.
 Encapsulation is the process of binding data (variables) and methods
(functions) together into a single unit (class) and restricting direct access to
some of the object’s component
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.

 There are different types of inheritance are there single inheritance, multiple
inheritance, multilevel inheritance, Hierarchical inheritance and Hybrid inheritance.
6. Polymorphism:
The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a method to be displayed in more than one form.
It allows the same function or method name to behave differently in different
situations.
o Same method name, different behaviour.
o Improves flexibility and code reusability.
o Achieved through method overloading and method overriding.
o Supports runtime and compile-time polymorphism.
o Reduces code complexity.

For example, A person at the same time can have different characteristics. Like a man
at the same time is a father, an employee. So the same person possesses different
behavior in different situations. This is called polymorphism.

Why do we need object-oriented programming?


● To make the development and maintenance of projects more effortless.

● To provide the feature of data hiding that is good for security concerns.
● We can solve real-world problems if we are using object-oriented programming.

● It ensures code reusability.


● It lets us write generic code: which will work with a range of data, so we don’t have
to write basic stuff over and over again.

You might also like