0

Why do we need a constructor for our class instead of declare variable or just put parameters into class and using that all?

27th Apr 2020, 8:27 AM
SwingsNFI
SwingsNFI - avatar
8 ответов
+ 2
Naufal Fatihul Ihsan you just created classes ,but you didn't actually tried out printing the result ,maybe play around with it and also learn why constructors are used,and you haven't even touched the oop concept in python atleast here ,I dunno where you got the idea of not using a constructor but also you didn't experimented yourself , And constructor let you pass value when creating an instance of class so you don't have to access the class everytime and pass the value on your own ,
27th Apr 2020, 9:23 AM
Abhay
Abhay - avatar
+ 1
~ swim ~ so I can do the second things than using initializer for just what you said? Or there's a rule that you must using OOP Concept?
27th Apr 2020, 9:57 AM
SwingsNFI
SwingsNFI - avatar
27th Apr 2020, 8:42 AM
Abhay
Abhay - avatar
0
Not really
27th Apr 2020, 8:45 AM
SwingsNFI
SwingsNFI - avatar
0
Do you have any code without using constructor and what you are talking about ,I never tried so just asking!
27th Apr 2020, 8:47 AM
Abhay
Abhay - avatar
27th Apr 2020, 8:59 AM
SwingsNFI
SwingsNFI - avatar
0
Abhay it just for example, not really to used it, but thanks, I just thought for the other way instead of using OOP Concept cause I'm new to constructor
27th Apr 2020, 9:54 AM
SwingsNFI
SwingsNFI - avatar
0
The answer you looking for would be, the init constructer initializes the variable, and thus gives the code a systematic order of arrangement and also it gets easy to understand the code .
29th Apr 2020, 4:31 AM
$layer
$layer - avatar