[Tutor] Help on class

bharath ks bharathks123 at yahoo.com
Fri Sep 27 16:07:39 CEST 2013


Hello,

May i know why object 'c' does not prompt for employee name and employee id in the following code
i get out put as 

Enter employee name:john
Enter employee id:56
Employee name is: john
Employee id is: 56
----------------------------------------------------
Employee name is: test
Employee id is: 1003
----------------------------------------------------
Employee name is: john
Employee id is: 56

class employee:

    emp_name=""
    emp_id=0
    def collect_name():
        return(input("Enter employee name:"))
   
    
    def collect_id():
        return(input("Enter employee id:"))
            
    def show(self):
        print("Employee name is:",self.emp_name)
        print("Employee id is:",self.emp_id)
        
    def __init__(self,name=collect_name(),id=collect_id()):
        self.emp_name=name
        self.emp_id=id
     
     

a=employee()
a.show()
print("----------------------------------------------------")
b=employee("test",1003)
b.show()
print("----------------------------------------------------")
c=employee()
c.show()


 

Thanks & BR,
Bharath Shetty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130927/495ae605/attachment.html>


More information about the Tutor mailing list