Python Programming Using Problem Solving by Harsh Bhasin

Python Programming Using Problem Solving by Harsh Bhasin

Author:Harsh Bhasin [Oswald Campesato]
Language: eng
Format: epub
Publisher: Mercury Learning and Information
Published: 2023-12-15T00:00:00+00:00


>>>

============ RUN C:/Python/Class/Constructor1.py ===============

Enter name  :Harsh

Enter age:28

Name : Harsh

Age : 28

Name: ABC

Age: 20

>>>

A parameterized constructor is one that takes arguments, for example, in the following code, the parameterized constructor, which takes two parameters name and age has been created. In order to assign the values to the Object, the instantiation must be of the form:

e2=employee('Naved', 32)

Note that while defining the parameterized __init__, the first parameter is always “self,” the rest of the parameters are the values to be assigned to different data members of the class. In the case of employee class, three parameters, “self,” “name,” and “age” are given.

Code:

>>>

class employee:

   def getdata(self):

      self.name=input('Enter name :')

      self.age=input('Enter age :')

   def putdata(self):

      print('Name :',self.name)

      print('Age :',self.age)

   def __init__(self, name, age):

    self.name=name

    self.age=age

   def __del__():

      print('Done')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.