• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

왜 detail_info를 출력할 때 마지막에 None이 찍히나요?

21.06.05 15:51 작성 조회수 83

0

안녕하세요. 클래스 메소드 심화 부분에 있는 Car 클래스 다루는 곳에서 None이 마지막에 출력되네요

class Car():
    """
    Car Calss
    Author : You Young Jae
    Data: 2021.06.06
    """
    # 클래스 변수
    car_count = 0

    def __init__(self, company, details):
        self._company = company
        self._details = details
        Car.car_count += 1
    
    def __str__(self):
        return 'str: {} - {}'.format(self._company, self._details)
    
    def __repr__(self):
        return 'repr: {} - {}'.format(self._company, self._details)

    def detail_info(self):
        print('Current Id: {}'.format(id(self)))
        print('Car Detail Info: {} {}'.format(self._company, self._details.get('price')))

    def __del__(self):
        Car.car_count -= 1

car1 = Car('Ferrari', {'color' : 'White', 'horsepower': 400, 'price': 8000})
car2 = Car('Bmw', {'color' : 'Black', 'horsepower': 270, 'price': 5000})
car3 = Car('Audi', {'color' : 'Silver', 'horsepower': 300, 'price': 6000})

# ID 확인
print(id(car1))
print(id(car2))
print(id(car3))

print(car1._company == car2._company)
print(car1 is car2)

print(dir(car1))
print(dir(car2))

print()
print()

print(car1.__dict__)
print(car2.__dict__)

print()
print()

print(Car.__doc__)

print()
print()

car1.detail_info()
car2.detail_info()

print()
print()

print(Car.detail_info(car1))
print(Car.detail_info(car2))

답변 1

답변을 작성해보세요.

0

이용주님의 프로필

이용주

질문자

2021.06.05

아 반환값이 없는데 print를 했기 떄문에 그랬던 것이네요. 감사합니다