Advertisement
Riju21

32_oop_python

May 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. # class , obj
  2. # -------------
  3.  
  4.  
  5. # with constructor
  6. # -----------------
  7.  
  8. # class Person():
  9. #     def __init__(self, fname, lname, idd):
  10. #         self.fname = fname
  11. #         self.lname = lname
  12. #         self.id = idd
  13. #         self.email = idd + '@gmail.com'
  14. #     def info(self):
  15. #         return ('firstname: {} , lastname: {}, id: {}, email: {}'.format(self.fname, self.lname, self.id, self.email))    
  16.  
  17. # p1 = Person('riju', 'chowdhury', '2015-1-60-169')
  18. # print(p1.info())
  19.  
  20.  
  21. # with fn
  22. # ---------
  23. # class Person():
  24. #     def info(self, fname, lname, idd):
  25. #         self.fname = fname
  26. #         self.lname = lname
  27. #         self.id = idd
  28. #         self.email = idd + '@gmail.com'
  29.  
  30. #         return ('{} {} {} {}'.format(self.fname, self.lname, self.id, self.email))
  31.  
  32. # p1 = Person()
  33. # print(p1.info('riju', 'chowdhury', '2015-1-60-169'))
  34.  
  35. # variable
  36. # -----------
  37.  
  38. class Person():
  39.     amount = 2.04
  40.     def info(self, fname, lname, idd):
  41.         self.fname = fname
  42.         self.lname = lname
  43.         self.id = idd
  44.         self.email = idd + '@gmail.com'
  45.  
  46.         return ('{} {} {} {}'.format(self.fname, self.lname, self.id, self.email))
  47.  
  48.     # def salaryCalc(self, salary):
  49.     #     self.total = salary * 2.04
  50.     #     return ('salary: {}'.format(self.total))
  51.     def salaryCalc(self, salary):
  52.         self.total = salary * Person.amount         # call variable
  53.         return ('salary: {}'.format(self.total))
  54.  
  55.  
  56. p1 = Person()
  57. print(p1.info('riju', 'chowdhury', '2015-1-60-169'))
  58. print(p1.salaryCalc(6000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement