Q:

Write a python program to determine which class a given Bus object belongs to.

belongs to collection: Python OOP Exercises

0

Check type of an object

Write a program to determine which class a given Bus object belongs to.

Given:

class Vehicle:
    def __init__(self, name, mileage, capacity):
        self.name = name
        self.mileage = mileage
        self.capacity = capacity

class Bus(Vehicle):
    pass

School_bus = Bus("School Volvo", 12, 50)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use Python’s built-in function type().

Solution:

class Vehicle:
    def __init__(self, name, mileage, capacity):
        self.name = name
        self.mileage = mileage
        self.capacity = capacity

class Bus(Vehicle):
    pass

School_bus = Bus("School Volvo", 12, 50)

# Python's built-in type()
print(type(School_bus))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PrettyPrint following JSON data using python progr... >>
<< Class Inheritance using python programming...