Skip to content

Commit 7cacfd5

Browse files
authored
added multiple constructor program
1 parent 7e56dea commit 7cacfd5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
# IT ISN'T NOT POSSIBLE TO DECLARE MULTIPLE INIT METHOD IF U DECLARE MULTIPLE INIT MTHD THEN PYTHON WILL CONSIDERED LAST INIT METHOD AS MAIN AND PREVIOUS INIT METHOD IS OVERWRITTEN BY LAST INIT METHOD
4+
5+
class Hello:
6+
# def __init__(self): pass # it is an empty method
7+
# def __init__(self, name): pass
8+
# def __init__(self, *args, **kwargs): pass # -- 1st
9+
10+
def __init__(self,name):
11+
self.name = name
12+
self.age = 10 # it is possible to declare attributes without passing as arguments in the function
13+
14+
15+
hello = Hello()
16+
hello = Hello('name', 'age', name = 'chaman') # -- 1st

0 commit comments

Comments
 (0)