[Python] <bound method Car.get_descriptive_name of <__main__.ElectricCar object at...

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    Error message that I get is as below:

    PS C:\Python Tutorials> & C:/Python311/python.exe "c:/Python Tutorials/C_and_O_Electric_Car.py"
    <bound method Car.get_descriptive_name of <__main__.ElectricCar object at 0x0000021A168CFC90>>


    Source Code :

    class Car:
    """A simple attempt to represent a car """

    def __init__(self,make,model,year):
    self.make = make
    self.model = model
    self.year = year
    self.odometer_reading = 0

    def get_descriptive_name(self):
    """Return a neatly formatted descriptive name"""
    long_name = f" {self.year} {self.make} {self.model}"
    return long_name.title()

    def read_odometer(self):
    """Print a statement showing the car's milage."""
    print(f"This car has {self.odometer_reading} miles on it")

    def update_odometer(self, milage):
    """Set the odometer value to the given value
    Reject the change it it tries to roll the odometer back"""
    if milage > self.odometer_reading:
    self.odometer_reading = milage
    else:
    print("You cant rollback the odometer!")

    def increment_odometer(self,miles):
    """Add the give amount to the odometer reading"""
    self.odometer_reading += miles

    class ElectricCar(Car):
    def __init__(self, make, model, year):
    super().__init__(make,model,year)

    my_tesla = ElectricCar('Tesla','Model S', 2019)
    print(my_tesla.get_descriptive_name)

    Continue reading...

Compartilhe esta Página