On Wed, Mar 6, 2019 at 10:01 AM Milt <t2 at netrh.com> wrote:
> The following code gives me unusual results - base on experience with C++.
> def __init__(self, color = None, miles = None):
> self.mileage = miles
> self.carColor = color
> myCar = Car('blue', 15000)
> myCar = Car(25000, 'orange')
> It appears that the constructor ignores the assignment statements and
> makes the assignment based on the ordering in the __init__ declaration.
Based on your experience with C++, what tells the compiler that you
can pass arguments in any order? Would you write multiple constructors
taking different arguments? Because you didn't do that here.
What you CAN do is call the constructor with keyword arguments:
But otherwise, Python (just like C++) will pass the arguments in the
order you wrote them.