Advertisement
class_connect

TEST

May 10th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | Source Code | 0 0
  1. #class.py
  2. class Riddhi:
  3.     def name(self):
  4.         print('Riddhi')
  5.     def age(self):
  6.         print(18)
  7.     def country(self):
  8.         print('Bangladesh')
  9.        
  10.        
  11. x = Riddhi()
  12. x.name()
  13. x.age()
  14. x.country()
  15.  
  16. x.y=21
  17. print(x.y)
  18. #print(x.k)
  19.  
  20. z = Riddhi()
  21. z.k=20
  22. print(z.k)
  23. #print(z.y)
  24.  
  25. #constructors.py
  26. class Riddhi:
  27.     def __init__(self, a, b, character):
  28.         self.a = a
  29.         self.b = b
  30.         self.c = character
  31.     def name(self):
  32.         return('Riddhi')
  33.     def age(self):
  34.         print(18)
  35.     def country(self):
  36.         print('Bangladesh')
  37.     def state(self):
  38.         print(f'This is {self.name()} a.k.a {self.c} from {self.country()}.')
  39.        
  40. x = Riddhi(10, 20, 'Nobody')
  41. x.name()
  42. x.age()
  43. x.country()
  44. x.state()
  45.  
  46. print(x.a)
  47. print(x.b)
  48. print(x.c)
  49.  
  50. #inheritance.py
  51. class Main:
  52.     def sub(self):
  53.         print('Inherited from Main function and called in 1st function')
  54.     def sub1(self):
  55.         print('Inherited from Main function and called in 2nd function')
  56.        
  57.        
  58. class subfirst(Main):
  59.     def fsincl(self):
  60.         print('This is defined in 1st function not inherited')
  61.  
  62.    
  63. class subsecond(Main):
  64.     pass    
  65.        
  66. first = subfirst()
  67. first.fsincl()
  68. first.sub()
  69. second = subsecond()
  70. second.sub1()
  71.  
  72.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement