파이썬/클래스

파이썬 클래스 2

watervin 2022. 1. 14. 09:45
class Car:
    count = 0 #클래스 멤버변수

    def __init__(self,name) -> None:
        self.name = name
        Car.count += 1
        

    @classmethod
    def outcount(cls):
            print(cls.count)

pride = Car("프라이드")
korando = Car("코란도")
Car.outcount()

class Car:
    @staticmethod
    def hello():
        print("오늘도 안전 운행 합시다.")

        count = 0

    def __init__(self,name) -> None:
        self.name = name
        Car.count += 1

    @classmethod
    def outcount(cls):
        print(cls.count)

Car.hello()

from unicodedata import name


class Human:
    def __init__(self,name,age) -> None:
        self.name = name
        self.age = age

    def __eq__(self, other) -> bool:
        return self.name == other.name and self.age ==other.age

kim = Human("김상형",29)
sang = Human("김상형",29)
moon = Human("문종민",44)

print(kim == sang)
print(kim == moon)

 

 

'파이썬 > 클래스' 카테고리의 다른 글

파이썬 클래스 2  (0) 2022.01.13
파이썬 클래스  (0) 2022.01.12