176k views
0 votes
Write codes to create a Vehicle with a constructor that will set data attributes, maxSpeed and mileage to 0. (python)

1 Answer

3 votes

Answer:

Here is the Python code to create a vehicle class with a constructor that initializes maxspeed and mileage to 0:

```

class Vehicle:

def __init__(self):

self.maxspeed = 0

self.mileage = 0

```

This constructor function takes no arguments, but initializes the data attributes `maxspeed` and `mileage` to 0.

You can then create an instance of this Vehicle class simply by calling the class constructor, like this:

```

mycar = Vehicle()

```

Now the `mycar` object has `maxspeed` and `mileage` set to 0, and you can modify these attributes as needed.

User Bogdan Bystritskiy
by
7.8k points