- #1
- 716
- 162
- TL;DR Summary
- I am learning about classes, and something about __init__ seems redundant-- I'm sure there's a reason for it, which is what I am looking for.
Here is an example code in python, describing a class of fruits:
If, in general, we ALWAYS do this:
why don't we just write
instead of adding the self.property1 = property1 etc?
Is there ever a time where we wouldn't follow the "general formula" in this post's second block of code? If not, is there a reason python can't just fill in the rest of the "formula" if given
?
Thank you!
Python:
class Fruits(object):
def __init__(self, color, taste):
self.color = color
self.taste = taste
If, in general, we ALWAYS do this:
Python:
class ExampleClass(object):
def __init__(self, property1, property2):
self.property1 = property1
self.property2 = property2
Code:
def __init__(self, property1, property2)
Is there ever a time where we wouldn't follow the "general formula" in this post's second block of code? If not, is there a reason python can't just fill in the rest of the "formula" if given
Code:
def __init__(self, property1, property2)
Thank you!