파이썬/클래스 3

파이썬 클래스 2

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()..

파이썬/클래스 2022.01.14

파이썬 클래스 2

모든 클래스는 object 클래스의 자식이다. class Human: def __init__(self,name,age) -> None: self.name = name self.age = age def intro(self): print(str(self.age) + "살" + self.name + "입니다.") def eat(self): print("식사를 합시다.") def __str__(self) -> str: return f'Human(name = {self.name}, age = {self.age})' class Student (Human): def __init__(self, name, age,stunum) -> None: super().__init__(name, age) self.stunum = s..

파이썬/클래스 2022.01.13

파이썬 클래스

클래스 정의 class 키워드로 정의 대문자로 시작하는 경우가 많음 파스칼 케이스 class Account: def __init__(self,balance): self.balance = balance def deposit(self,money): self.balance += money def inquire(self): print(f'잔액은 {self.balance}원 입니다.') def main(): account = Account(8000) account.deposit(1000) account.inquire() shihan = Account(8000) shihan.deposit(1000) shihan.inquire() nonghyup = Account(12000000) nonghyup.inquire() ..

파이썬/클래스 2022.01.12