Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #class.py
- class Riddhi:
- def name(self):
- print('Riddhi')
- def age(self):
- print(18)
- def country(self):
- print('Bangladesh')
- x = Riddhi()
- x.name()
- x.age()
- x.country()
- x.y=21
- print(x.y)
- #print(x.k)
- z = Riddhi()
- z.k=20
- print(z.k)
- #print(z.y)
- #constructors.py
- class Riddhi:
- def __init__(self, a, b, character):
- self.a = a
- self.b = b
- self.c = character
- def name(self):
- return('Riddhi')
- def age(self):
- print(18)
- def country(self):
- print('Bangladesh')
- def state(self):
- print(f'This is {self.name()} a.k.a {self.c} from {self.country()}.')
- x = Riddhi(10, 20, 'Nobody')
- x.name()
- x.age()
- x.country()
- x.state()
- print(x.a)
- print(x.b)
- print(x.c)
- #inheritance.py
- class Main:
- def sub(self):
- print('Inherited from Main function and called in 1st function')
- def sub1(self):
- print('Inherited from Main function and called in 2nd function')
- class subfirst(Main):
- def fsincl(self):
- print('This is defined in 1st function not inherited')
- class subsecond(Main):
- pass
- first = subfirst()
- first.fsincl()
- first.sub()
- second = subsecond()
- second.sub1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement