0% found this document useful (0 votes)
1 views27 pages

Python Module 5

The document outlines the syllabus for a Python programming course, focusing on Object-Oriented Programming (OOP) concepts such as classes, objects, and methods. It includes detailed explanations of class definitions, object creation, attributes, and the mutability of objects, along with examples and code snippets. Additionally, it covers the concepts of pure functions and modifiers, providing practical examples related to time management in programming.

Uploaded by

yashatwood
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)
1 views27 pages

Python Module 5

The document outlines the syllabus for a Python programming course, focusing on Object-Oriented Programming (OOP) concepts such as classes, objects, and methods. It includes detailed explanations of class definitions, object creation, attributes, and the mutability of objects, along with examples and code snippets. Additionally, it covers the concepts of pure functions and modifiers, providing practical examples related to time management in programming.

Uploaded by

yashatwood
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/ 27

Introduction to python programming- 22PLC105B/205B AY:2023-24

MODULE 5
SYLLABUS:

Classes and objects, Programmer-defined types, Attributes, Rectangles, Instances as return values,
Objects are mutable, Copying
Classes and functions, Time, Pure functions, Modifiers, Prototyping versus planning

Classes and methods, Object-oriented features, Printing objects, Another example, A more
complicated example,The init method, The str method, Operator overloading, Type-based
dispatch, Polymorphism, Interface and implementation,

Textbook: Allen B. Downey, “Think Python: How to Think Like a Computer Scientist”, 2nd
Edition, Green Tea Press, 2015. (Available under CC-BY-NC license at
http://greenteapress.com/thinkpython2/thinkpython2.pdf) (Chapters 13, 15, 16, 17, 18)
(Download pdf/html files from the above links)

Object Oriented Programming ( OOPs)


• In oops there are three important terms we use repeatedly
• Class

• Object

• Reference Variable

A Better way to understand the concept of Class and Object.

Mould is a Class
Ganesha Idols are objects

Dept of CSE(IOT), MVIT 1


Introduction to python programming- 22PLC105B/205B AY:2023-24

Plan is a Class

Villas Constructed Using Plan are Objects

Pan is a Class

Recipes Prepared Using Pan are Objects

Class

• Class is a blue print for objects.


• Class Represents properties (attributes) (Variables ) and actions(behaviors) (Methods)
which are required for objects.
Dept of CSE(IOT), MVIT 2
Introduction to python programming- 22PLC105B/205B AY:2023-24

Object
• Object is the physical existence or an instance of class.
• We can create any number of objects to a class

Reference Variable

Specifications for the TV is a class


TV is an Object.

Let’s Consider a situation..


Here is a remote to control the above TV(Object).
If the remote is lost then you can buy a new remote.
Again if you find the old remote, you can use both
the remotes to control the TV.

In the Same way, reference variables are like


remotes.
Reference variables are to access the objects.
For one object you can have multiple reference
Variables.

• Reference Variable which can be used to refer the object.

• Using reference variables we can perform required operations on the objects.


• By using reference variable we can access properties and methods of an object.
• An Object can have multiple reference variables.

• Objects without reference variables are useless.

********** above examples are only for understanding the concept in a better way, don’t
write them in exam*************

Dept of CSE(IOT), MVIT 3


Introduction to python programming- 22PLC105B/205B AY:2023-24

Chapter 1: Classes and objects


1.1 Python Classes/Objects

Class:
 A Class is like an object constructor, or a "blueprint" for creating objects.
 A programmer-defined type is also called a class.
 A class definition looks like this:
class Point:
"""Represents a point in 2-D space."""

 The header indicates that the new class is called Point.


 The body is a docstring that ex-plains what the class is for.
 You can define variables and methods inside a class definition,

1.1.1 How to define a class? (Syntax)

Use class keyword


class classname(any name):
‘ ‘ ‘ documentation string ’ ’ ’  *first thing what you can take is
Variables *It represents description of the class
Methods *use Either three single or double quotes

 Variables are Properties / Attributes required for every object


 Methods are Actions / Behavior required for every object

1.1.2 How to create an object? (Syntax)


object_name = classname(*args)
Creating a new object is called instantiation, and the object is an instance of the class.

>>>blank = Point()
>>>blank
Output:
< main .Point object at 0xb7e9d3ac>
• When you print an instance, Python tells you what class it belongs to and where it is stored
in memory (the prefix 0x means that the following number is in hexadecimal).
• The return value is a reference to a Point object, which we assign to blank.

Example 1:
Create a Class:
• To create a class, use the keyword class

Dept of CSE(IOT), MVIT 4


Introduction to python programming- 22PLC105B/205B AY:2023-24

Example:
class My Class:
x=5
Create Object:
• Now we can use the class named My Class to create objects
• Create an object named p1, and print the value of x
Example:
p1 = MyClass()
print(p1.x)

Complete Program
class MyClass:
x=5
p1 = MyClass()
print(p1.x)

Output:
5

1.1.3 How to create attributes?

 You can assign values to an instance using dot notation:


>>> blank. x = 3.0
>>> blank. y = 4.0
 Here we are assigning values to named elements of an object.
 These elements are called attributes.

Let’s write complete program


class Point:

"""Represents a point in 2-D space."""


blank = Point()
blank. x = 3.0
blank. y = 4.0

1.1.4 How to write an object diagram?

• The variable blank refers to a Point object, which contains two attributes.

Dept of CSE(IOT), MVIT 5


Introduction to python programming- 22PLC105B/205B AY:2023-24

• Each attribute refers to a floating-point number.

1.2 Rectangles

Example:

class Rectangle:
‘ ‘ ‘ Doc String – Optional ’ ’ ’
box = Rectangle()
box. width = 100.0
box. height = 200.0
box. corner =
Point()box. corner.
x = 0.0
box. corner. y = 0.0

 The expression box. corner. x means, “Go to the object box refers to and select
theattribute named corner; then go to that object and select the attribute named x.”
 An object that is an attribute of another object is embedded.
1.3 Instances as return values

Functions can return instances.

For example, find_ center takes a Rectangle as an argument and returns a Point
thatcontains the coordinates of the center of the Rectangle:
Example :

class Point:
"""Represents a point in 2-D space."""
blank = Point()

blank. x = 3.0

blank. y = 4.0

class Rectangle:
'''Doc String – Optional'''
box = Rectangle()box.

width = 100.0
box. height = 200.0

box. corner =Point()


box. corner. x = 0.0
box. corner. y = 0.0

Dept of CSE(IOT), MVIT 6


Introduction to python programming- 22PLC105B/205B AY:2023-24

def find_ center(rect):

p = Point()
p. x = rect. corner. x + rect. width/2
p. y = rect. corner. y + rect. height/2

return p # Here p is an instance and can be returned.


def print_ point(p):

print('(%g, %g)' % (p. x,p.y))


center = find_ center(box)
print_point(center)

Output:
(50, 100)

1.4 Objects are mutable (You can modify)


• You can also write functions that modify objects.
• For example, grow_ rectangle takes a Rectangle object and two numbers, d width
andd height, and adds the numbers to the width and height of the rectangle:

Example:
class Point:
"""Represents a point in 2-D space."""
blank = Point()
blank. x = 3.0
blank. y = 4.0
class Rectangle:
'''Doc String – Optional'''
box = Rectangle()
box. width = 100.0
box. height = 200.0
box. corner =Point()
box. corner. x = 0.0
box. corner. y = 0.0

box. width = box. width + 50 #objects are mutable


box. height = box. height + 100 #objects are mutable

def find_ center(rect):

Dept of CSE(IOT), MVIT 7


Introduction to python programming- 22PLC105B/205B AY:2023-24

p = Point()
p. x = rect. corner. x + rect. width/2
p. y = rect. corner.y+rect.height/2
return p

def print _ point(p):


print('(%g, %g)' % (p. x, p. y))

center = find_center(box)
print_point(center)

print(box.width,box.height)

Output:

75, 150
150.0 300.0

1.5 Copying
• Aliasing can make a program difficult to read because changes in one place might have
unexpected effects in another place.
• It is hard to keep track of all the variables that might refer to a given object.
• Copying an object is often an alternative to aliasing.
• The copy module contains a function called copy that can duplicate any object:

1.5.1 Shallow Copy


• If you use copy. copy to duplicate a Rectangle, you will find that it copies the
Rectangleobject but not the embedded Point.
>>> box2 = copy. copy(box)
>>> box2 is box
False
>>> box2.corner is box. corner
True

1.5.2 Deep Copy


>>> box3 = copy. Deep copy(box)
>>> box3 is box
False

Dept of CSE(IOT), MVIT 8


Introduction to python programming- 22PLC105B/205B AY:2023-24

>>> box3.corner is box. corner


False
• box3 and box are completely separate objects.

Dept of CSE(IOT), MVIT 9


Introduction to python programming- 22PLC105B/205B AY:2023-24

Chapter 2: Classes and functions


2.1 Time
• As another example of a programmer-defined type, we’ll define a class called Time that
records the time of day.
class Time:
"""Represents the time of day.
attributes: hour, minute, second
"""
Object for class Time
We can create a new Time object and assign attributes for hours, minutes, and seconds:
time = Time ()
time. hour = 11
time. minute = 59
time. second = 30

Complete Program:
class Time:
"""Represents the time of day.
attributes: hour, minute, second
"""
time = Time ()
time. hour = 11

time. minute = 59
time. second = 30
The state diagram for the Time object looks like

2.2 Types of Functions:


There are two types of functions

 Pure Functions
 Modifiers

2.2.1 Pure Functions

Dept of CSE(IOT), MVIT 10


Introduction to python programming- 22PLC105B/205B AY:2023-24

• To understand the concept we will define a class called Time that records the time of day.
• The class definition looks like this and We can create a new Time object or instance, also
create and assign attributes for hours, minutes, and seconds.

Example not a pure function, it’s a normal program


class Time:
"""Represents the time of day. attributes: hour, minute, second"""
time = Time()
time.hour = 11
time.minute = 59
time.second = 30

print ("Hour: %g" % (time.hour))


print ("Minute: %g" % (time.minute))
print ("Second: %g" % (time.second))
Output
Hour: 11
Minute: 59
Second: 30

• The function that creates a new Time object, initializes its attributes with new values and
returns a reference to the new object.
• This is called a pure function because it does not modify any of the objects passed to it as
arguments and it has no effect, like displaying a value or getting user input, other than
returning a value.
Pure functions example
class Time:
"""Represents the time of day. attributes: hour, minute, second""“

def add_ time(t1, t2):


sum = Time()
sum. hour = t1.hour + t2.hour
sum.minute = t1.minute + t2.minute
sum. second = t1.second +t2.second
return sum
def print_time(t):
print('Hour:', t.hour, '\nMinute: ', t.minute, '\nSeconds: ', t.second)
start = Time()
start.hour = 9
start.minute = 45
start.second = 30
duration = Time()
duration.hour = 1

Dept of CSE(IOT), MVIT 11


Introduction to python programming- 22PLC105B/205B AY:2023-24

duration. minute = 35
duration. second = 0
done = add_ time(start,duration)
print_time(done)

Output
Hour: 10
Minute: 80
Second: 30

Pure functions example explanation


• To demonstrate this function, I will create two Time objects (instances):
• the first one is, start contains the start time of a movie which is 9 hours, 45 minutes,
and 30 seconds
• and another is duration contains the run time of the movie, which is 1 hour 35
minutes.
• The add_time() function accepts two-time objects, creates a new object sum.
• Add the two objects start time and duration assign result to sum and finally returns the
sum.
• Here add_time() function is not modifying the passed objects, hence it is called pure
function.

Problem identified in the previous Example

• The result, 10:80:00 might not be what you were hoping for.
• The problem is that this function does not handle the cases such as the number of seconds
or minutes adds up to more than sixty.
• When that happens, we have to “carry” the extra seconds into the minute column or the
extra minutes into the hour column.
• The next example handles such issues effectively.
Solution to the problem
class Time:
"""Represents the time of day. attributes: hour, minute, second“””

def add_time(t1, t2):


sum = Time()

sum.hour = t1.hour + t2.hour


sum.minute = t1.minute + t2.minute
sum.second = t1.second + t2.second

Dept of CSE(IOT), MVIT 12


Introduction to python programming- 22PLC105B/205B AY:2023-24

if sum.second >= 60:

sum.second -= 60

sum.minute += 1
if sum.minute >= 60:
sum.minute -= 60

sum.hour += 1
return sum

def print_time(t):

print('Hour:', t.hour, '\nMinute: ', t.minute, '\nSeconds: ', t.second)

start = Time()
start.hour = 9
start.minute = 45

start.second = 0
duration = Time()
duration.hour = 1

duration.minute = 35
duration.second = 0

done = add_time(start, duration)


print_time(done)

Output
Hour: 11
Minute: 20

Second: 00
2.2.2 Modifiers
• Sometimes it is useful for a function to modify the objects it gets as parameters.
• In that case, the changes are visible to the caller.

• Functions that work this way are called modifiers.

Example:

Dept of CSE(IOT), MVIT 13


Introduction to python programming- 22PLC105B/205B AY:2023-24

In the below example: increment, which adds a given number of seconds to a Time
object, can be written naturally as a modifier.
def increment(time, seconds):
time.second += seconds

if time.second >= 60:


time.second -= 60

time.minute += 1
if time.minute >= 60:

time.minute -= 60
time.hour += 1

Complete Program
class Time:

"""Represents the time of day. attributes: hour, minute, second"""


def increment(time, seconds):

time.second += seconds

m = int (time.second/60)

time.second = time. Second (m*60)


time. Minute += m
h = int (time.minute/60)
time.minute = time.minute - (h*60)

time.hour += h
def print_time(t):

print('Hour:', t.hour, '\nMinute: ', t.minute, '\nSeconds: ', t.second)


start = Time()

start.hour = 9
start.minute = 45

start.second = 0

seconds = 5000

Dept of CSE(IOT), MVIT 14


Introduction to python programming- 22PLC105B/205B AY:2023-24

#print_time(start)

increment(start, seconds)
print_time(start)

Output

Hour: 11
Minute: 20

Second: 00

2.3 Prototyping versus planning


• Here is a function that converts Times to integers:
def time_to_int(time):

minutes = time.hour * 60 + time.minute


seconds = minutes * 60 + time.second

return seconds

• And here is a function that converts an integer to a Time ( recall that div mod divides
the first argument by the second and returns the quotient and remainder as a tuple).
def int_to_time(seconds):
time = Time()

minutes, time.second = div mod(seconds, 60)


time.hour, time.minute = div mod(minutes,60)
return time

• Once you are convinced they are correct, you can use them to rewrite add_time:
def add_time(t1, t2):

seconds = time_to_int(t1) + time_to_int(t2)

return int_to_time(seconds)

Dept of CSE(IOT), MVIT 15


Introduction to python programming- 22PLC105B/205B AY:2023-24

Chapter 3: Classes and methods


• Python is an object-oriented programming language, which means that it provides features
that support object-oriented programming, which has these defining characteristics:

• Programs include class and method definitions.


• Most of the computation is expressed in terms of operations on objects.

• Objects often represent things in the real world, and methods often correspond to the ways
things in the real world interact.

Difference between Methods and Functions


• Methods are defined inside a class definition in order to make the relationship between the
class and the method explicit.

• The syntax for invoking a method is different from the syntax for calling a function.

3.1 Printing objects


class Time:

"""Represents the time of day."""


def print_time(time):

print('%.2d:%.2d:%.2d' % (time. Hour, time. Minute, time.


Second))To call this function, you have to pass a Time object as an argument:
>>> start = Time()

>>> start.hour = 9
>>> start.minute = 45
>>> start.second = 00

>>> print_time(start)

09:45:00

To make print_time a method, all we have to do is move the function definition inside the
class definition.
• Notice the change in indentation.
class Time:

def print_time(time):
print('%.2d:%.2d:%.2d' % (time.hour, time.minute, time.second))

Now there are two ways to call print_time.

Dept of CSE(IOT), MVIT 16


Introduction to python programming- 22PLC105B/205B AY:2023-24

The first (and less common) way is to use function syntax:


>>> Time.print_time(start)

09:45:00
The second (and more concise) way is to use method syntax:
>>> start.print_time()

09:45:00

3.2 self
 Most commonly used python variable
 Is a reference variable, which is always pointing to current object.
 In python, if you want to access a object we need a reference variable and it is used within
a class.
 Self is a reference variable, which is always pointing to current object.
 Within a python class, if you want to access current object, you require self-reference
variable.

Example 1:
class Test:
def init (self):

print('Address of object pointed by self:', id(self))


t=Test() # use t is only outside of the class.
print('Address of object pointed by t:',id(t))

Output:

Address of object pointed by self: 1541619157904


Address of object pointed by t: 1541619157904
Example 2:
class Test:

def init (self):


print(‘constructor’)
def m1(self,x):

print(‘x value’,x)
t = Test()

Dept of CSE(IOT), MVIT 17


Introduction to python programming- 22PLC105B/205B AY:2023-24

t.m1(10)

Output:

constructor
x value 10

3.3 _ _init_ _ ( Python Constructor )


• Constructor is a special method in python.

• The name of a constructor is init


• In JAVA, the name of the constructor is always the name of the class.

• This constructor will be executed automatically when the object is created. No need to call
the constructor explicitly.
• Constructor will be executed Once per Object.

Example:
class Test:
def init (self):
print(‘constructor execution’)
t1 = Test()

t2 = Test()
t3 = Test()

Main Purpose of Constructor


• Just to declare & initialize instance variables

Example:
class student:
def init (self,name,rollno,marks):

print(‘creating instance variables and performing initialization’)


self.name = name
self.rollno = rollno

self.marks = marks

s1 = student(‘sunny’,101,90)
print(s1.name,s1.rollno,s1.marks)

Dept of CSE(IOT), MVIT 18


Introduction to python programming- 22PLC105B/205B AY:2023-24

Output:

creating instance variables and performing initialization


sunny 101 90

3.4 The _str_ Method


• str is a special method, like init , that is supposed to return a string representation
of an object.
• str is a reserved function in Python that returns the readable form of the object in the
string format.

Let’s take an Example without str:


class Demo:

def init (self,name,addr):


self.name=name

self.addr=addr

obj=Demo('divya','Bengaluru')
print(obj)

output:

< main .Demo object at 0x0000022E987F3C90>


Another Example:
class Demo:
def init (self,name,addr):
self.name=name

self.addr=addr
obj=Demo('divya','Bengaluru')
print(obj.name,obj.addr)

Output:

divya Bengaluru

Example (_ _str_ _):


class Demo:

Dept of CSE(IOT), MVIT 19


Introduction to python programming- 22PLC105B/205B AY:2023-24

def init (self,name,addr):

self.name=name

self.addr=addr

def str (self):


s = 'name='+self.name+'\nAddress='+self.addr

return s

obj=Demo('divya','bengaluru')

print(obj) #object will return the string

Output:
name=divya
Address=Bengaluru

3.5 Operator Overloading


• We can use same operator for multiple purposes.

Example:
>>>print(10+20)

>>>print(‘Divya’+’Raj’)
We are using same operator for multiple purposes.

• Operator Overloading means giving extended meaning beyond their predefined


operational meaning.
• For example operator + is used to add two integers as well as join two strings and merge
two lists. It is achievable because ‘+’ operator is overloaded by int class and str class.

• You might have noticed that the same built-in operator or function shows different
behaviour for objects of different classes, this is called Operator Overloading.

Example :
class Book:
def init (self,pages):

self.pages=pages
b1 = Book(100)

b2 = Book(200)

Dept of CSE(IOT), MVIT 20


Introduction to python programming- 22PLC105B/205B AY:2023-24

print(b1+b2)

OUTPUT:
Traceback (most recent call last):

File "E:/operatoroverload.py", line 6, in <module>


print(b1+b2)

TypeError: unsupported operand type(s) for +: 'Book' and 'Book'


Example 1: (Preferably write this on exam)
class Book:
def init (self,pages):

self.pages=pages

def add (self,other):

total_pages=self.pages+other.pages
return total_pages
b1 = Book(100)
b2 = Book(200)

print(b1+b2)

OUTPUT:

300

Example 2:
class A:
def init (self, a):
self.a = a

# adding two objects

def add (self, o):


return self.a + o.a

ob1 = A(1)
ob2 = A(2)
ob3 = A("Geeks")

Dept of CSE(IOT), MVIT 21


Introduction to python programming- 22PLC105B/205B AY:2023-24

ob4 = A("For")

print(ob1 + ob2)

print(ob3 + ob4)

Output:
3
GeeksFor

3.6 Polymorphism
• Very important for day to day coding.

• Poly – Many
• Morphs – Forms
• “one name but many forms”

• One of the best non technical example for POLYMORPHISM is YOURSELF.


• Operator overloading and Overriding are the best example for Polymorphism.

3.6.1 Polymorphism can be achieved through inheritance


• In Python, polymorphism refers to the ability of objects of different classes to be treated
as objects of a common base class.

Example 1: Overriding
class P:

def eat(self):

print(‘idly’)
class C(P):
def eat(self):

print(‘Dosa’)
c=C()

c. eat()
Output:

Dosa

Example 2:

Dept of CSE(IOT), MVIT 22


Introduction to python programming- 22PLC105B/205B AY:2023-24

class Animal:

def init (self, name):


self.name = name

def speak(self):
pass

class Dog(Animal):
def speak(self):

return 'Woof!'
class Cat(Animal):

def speak(self):
return 'Meow!'

def animal_speak(animal):
print(animal.speak())
dog = Dog('Fido')

cat = Cat('Whiskers')
animal_speak(dog) # prints "Woof!“

animal_speak(cat) # prints "Meow!"

Output:

Woof!
Meow!

Explanation:
• In this example, the Animal class serves as a base class for the Dog and Cat classes.

• The speak method is defined in the base class, but overridden in the subclasses to provide
unique behavior.

• The animal_speak function can take any object that is an instance of the Animal class or
any of its subclasses, and it will call the speak method on that object, which will in turn
call the appropriate overridden version of the method.

3.7 Type-based dispatch


• A programming pattern that checks the type of an operand and invokes different functions for
different types.

Dept of CSE(IOT), MVIT 23


Introduction to python programming- 22PLC105B/205B AY:2023-24

• Type-based dispatch in Python is a technique used to call different functions based on the
type of the input arguments.

• This can be done using the built-in function "isinstance()" which takes an object and a class
or tuple of classes as arguments, and returns True if the object is an instance of any of the
classes.

Here's a simple example 1:


def add_numbers(a, b):

if isinstance(a, int) and isinstance(b, int):


return a + b

elif isinstance(a, str) and isinstance(b, str):

return a + b
else:
raise ValueError("Invalid input types")

print(add_numbers(1, 2))
print(add_numbers("hello", "world"))

Output:
3

helloworld

• Type-based dispatch is useful when you want to separate the implementation details of
different types from the main logic of the program.

• It allows you to write more flexible and extensible code by decoupling the type of the
objects from the behavior of the program.

Dept of CSE(IOT), MVIT 24


Introduction to python programming- 22PLC105B/205B AY:2023-24

3.8 Interface and implementation


 At a high level, an interface acts as a blueprint for designing classes. Like
classes, interfaces define methods.
 Unlike classes, these methods are abstract. An abstract method is one that the
interface simply defines.
 It doesn’t implement the methods.
 This is done by classes, which then implement the interface and give concrete
meaning to the interface’s abstract methods.
 At a high level, an interface acts as a blueprint for designing classes. Like
classes, interfaces define methods
3.9 Inheritance
• Inheritance is the ability to define a new class that is a modified version of an existing
class.

• One of the core concepts in object-oriented programming (OOP) languages is inheritance.

• Inheritance is the capability of one class to derive or inherit the properties from another
class.

• It provides the reusability of a code. We don’t have to write the same code again and again.
Also, it allows us to add more features to a class without modifying it.

Python Inheritance Syntax


Class BaseClass:
#Body

Class DerivedClass(BaseClass):
#Body

Example 1:
class Person(object):
# Constructor

def init (self, name, id):


self.name = name
self.id = id

# To check if this person is an employee

Dept of CSE(IOT), MVIT 25


Introduction to python programming- 22PLC105B/205B AY:2023-24

def Display(self):

print(self.name, self.id)
# Driver code

emp = Person("Satyam", 102) # An Object of Person


emp.Display()

Output:
Satyam 102

Dept of CSE(IOT), MVIT 26


Introduction to python programming- 22PLC105B/205B AY:2023-24

VTU question paper Questions


1. What is Class? How do we define a class in Python? How to instantiate the class and how
class members are accessed? (July/August 2022 – 8M) (Feb/March 2022 – 8M)
2. Write a python program that uses datetime module within class, takes a birthday as input
and print users age and the number of days, hours, minutes and seconds until their next
birthday. (July/August 2022 – 7M)
3. Illustrate the concept of modifier with python code. (July/August 2022 – 5M)
4. Explain _ _init_ _ and _ _str_ _ method with an example Python program. (July/August
2022 – 8M) (Feb/March 2022 – 8M)
5. What are Polymorphic functions? Explain with code snippet. (July/August 2022 – 6M)
6. Illustrate the concept of inheritance with example. (July/August 2022 – 6M)
7. Write a Python program to add and multiply two complex number objects using operator
overloading concepts. (Feb/March 2022 – 8M)
8. Discuss type-based dispatch in a python. (Feb/March 2022 – 6M)
9. What is pure function? Illustrate the same with an example. (Feb/March 2022 – 6M)
10. Explain the concept of polymorphism with suitable example. (Feb/March 2022 – 6M)
11. What is class, object, attributes. Explain copy.copy() with example. (Jan/Feb 2021 – 6M)
12. Demonstrate pure functions and modifiers with example. (Jan/Feb 2021 – 8M)
13. Use datetime module to write a program that gets the current date and prints the day of the
week. (Jan/Feb 2021 – 6M)
14. Explain operator overloading and polymorphism with examples. (Jan/Feb 2021 – 8M)
15. Illustrate the concepts of inheritance and class diagrams with examples. (Jan/Feb 2021 –
8M)
16. Write a function called print time that takes a time object and print it in the form
hour:minute:second (Jan/Feb 2021 – 4M)

ALL THE BEST

Dept of CSE(IOT), MVIT 27

You might also like