Python init

Asked 2 years ago, Updated 2 years ago, 17 views

In the same conditions as above, I coded as below, but do I have to include renting a car in one init?(I couldn't do it when it wasn't a new car and a new car yet.)


class Car():

    def max_fuel(self,maxfuel):
        self.maxfuel = maxfuel

    def fuel_economy(self,fueleconomy):
        self.fueleconomy = fueleconomy

class Sonata(Car):

    def max_passengers(self,maxpassengers):
        self.maxpassengers=maxpassengers

    def __init__(self,maxfuel,fueleconomy,maxpassengers):
        self.maxfuel = 55
        self.fueleconomy = 12
        self.maxpassengers = 4
    ```

python

2022-09-20 16:00

1 Answers

I think whether you put it in or not depends on how you organize the code.

You will have to put it in to distinguish whether it is a new car or not from the first choice, and if you are going to distinguish whether it is a new car by further work, you will not have to put it in.


2022-09-20 16:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.