+ 1
Need explanation anyone !
Class A def__init__(a,b,c): Print(b) A(8,3)
3 Antworten
0
What is the advantages of using init method
0
'Class' should be lower case
':' after defining the class too. Itll look like
class A:
When you write the __init__ method:
it needs a space in between 'def' and '__init__'
You also need the parameter 'self'
itll look like:
class A:
def __init__(self,a,b,c):
Then you need to assign your parameters except for 'self' like so.
class A:
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
example = A(1,2,3)
print(example.b)
2
0
Every time you create a new instance of a class, the __init__ method basically sets up the basic values of the instance. The advantages arent clearly seen through such a small program. But the more complex your program is, the more useful oop is going to be to you.