Application Development using Python (18CS55) VTU Questions and Solutions - 3
1. What is class, object. Explain copy.copy() with an example code. A class is a user-defined blueprint or prototype from which objects are created. 2Marks An Object is an instance of a Class. A class is like a blueprint while an instance is a copy of the class with actual values. Copying an object is often an alternative to aliasing. The copy module contains a function called copy that can duplicate any object: p1 = Point() p1.x = 3.0 p1.y = 4.0 import copy p2 = copy.copy(p1) p1 and p2 contain the same data, but they are not the same Point. print_point(p1) (3, 4) print_point(p2) (3, 4) p1 is p2 False 2. Demonstrate pure functions and modifiers with example codes 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. Example code (3 Marks) def add_time(t1, t2): sum = Time() sum.hour = t1.ho...