0% found this document useful (0 votes)
144 views5 pages

OOP Concepts and Decision Making in Python

This document discusses object-oriented programming (OOP) concepts in Python including classes, objects, data types, access specifiers, inheritance, polymorphism, and decision-making statements. It defines a class as a blueprint for objects and an object as an instance of a class. Python data types include integers, floats, characters, strings, lists and dictionaries. Access specifiers include public, which can be accessed from outside a class, and private, which prefixes names with double underscores. The four pillars of OOP - abstraction, encapsulation, inheritance, and polymorphism - are also explained. Decision-making statements like if, if-else, and nested if-else are used to control program flow based on conditions.

Uploaded by

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

OOP Concepts and Decision Making in Python

This document discusses object-oriented programming (OOP) concepts in Python including classes, objects, data types, access specifiers, inheritance, polymorphism, and decision-making statements. It defines a class as a blueprint for objects and an object as an instance of a class. Python data types include integers, floats, characters, strings, lists and dictionaries. Access specifiers include public, which can be accessed from outside a class, and private, which prefixes names with double underscores. The four pillars of OOP - abstraction, encapsulation, inheritance, and polymorphism - are also explained. Decision-making statements like if, if-else, and nested if-else are used to control program flow based on conditions.

Uploaded by

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

Chapter- 2

OOP in Python
I. Answer the following
1. What is a class?
Ans: A class is a blueprint for creating objects. Class defines the properties and action of
an object. Properties are represented by variables and action by methods in the class.
2. What is an object?
Ans: An object is the instance of a class. Objects will have properties and actions. Object
is a model of the concept, process or things in the real world.
3. What do you mean by datatypes in Python?
Ans: Data types are the classification or categorization of data items. It represents the
kind of value that tells what operations can be performed on a particular data. Variables
can store data of different types. They are integer, float, character, string, list and
dictionary.
4. Explain access specifiers.
Ans: Access modifiers or specifiers are used to implement the concept of data hiding in
object-oriented programming. There are two types of access specifiers in Python: Public
and Private.
Public: Public property and methods in a class can be accessed from outside using object
and dot operator. All the methods and properties are public by default.
Private: To make an entity private, prefix the name with double underscore (__). Private
methods and properties cannot be accessed from outside using dot operator.
5. What do you mean by Object Oriented Programming? Explain with example.
Ans: Object Oriented Programming (OOP) is a style of programming that focuses on
using objects to design and build applications. It gives importance to data rather than
writing instructions to complete a task. An object is a thing or idea that we want to model
in our program. Object can be anything. Ex: employee, bank account, etc.
6. Explain the four pillars of OOP.
Ans: The four pillars of OOP are
i. Abstraction
ii. Encapsulation
iii. Inheritance
iv. Polymorphism
Abstraction is a process of hiding unnecessary details of an object from the user and
reveling the relevant data.

1
Encapsulation is a process of wrapping data and methods that operate on the data into a
single unit.
Inheritance is a mechanism in which one class acquires the property of another class. It
facilitates reusability of code and is an important concept of OOP.
Polymorphism is the ability of an object to take many forms. Methods bearing the same
name, will have different behaviors.
7. What is inheritance?
Ans: Inheritance is a mechanism in which one class acquires the property of another
class. With inheritance we can reuse the fields and methods of the existing class. Create a
class by deriving from an existing class. All the methods and properties are accessible
from the child class. It helps to avoid the duplication of code.
8. What is polymorphism?
Ans: Polymorphism is the ability of an object to take many forms. Methods bearing the
same name, will have different behaviors.
9. What is decision making statements?
Ans: Decision making statements are used to control the flow of execution of the
program depending upon the given condition.
There are three types of decision-making statement.
1.if statements
2.if-elsestatements
3.Nestedif-elsestatement

************************************************************************
Decision Making Statement:
Decision making statement used to control the flow of execution of program depending
upon condition.
There are three types of decision-making statements.
1.ifstatements
2.if-elsestatements
3.Nested if-else statement
1.if statements
An if statement is a programming conditional statement that, if proved true, performs a
function or displays information.

2
Syntax:
if(condition):
statement
[statements]
e.g.
nootbooks= 2
if(nootbooks== 2):
print('You have two books’)
2. if-else Statements
If-else statement executes some code if the test expression is true (nonzero) and some other
code if the test expression is false.

Syntax:
if(condition):
statements
else:
statements

3
e.g.
a=10
if(a < 100):
print(‘less than 100')
else:
print(‘more than equal 100')
# Program to find the given number is even or not.
a=int(input(“Enter a number”)
if(a%2)==0:
print(“The given number is even”)
else:
print(“The given number is odd”)
3. Nested if-else statement
The nested if...else statement allows you to check for multiple test expressions and execute
different codes for more than two conditions.

Syntax:
if(condition):
statements
elif(condition):
statements
else:
statements

4
Eg:
A=int(input(“Enter a number”)
B=int(input(“Enter a number”)
C=int(input(“Enter a number”)
if(A>B):
print(“A is greater”)
elif(B>C):
print(“B is greater”)
else:
print(“C is greater”)
**************************************************************************

You might also like