목록파이썬 중급 개념 (5)
♠Developer blog♠
클래스 변수를 코딩 중 수정하기보단, 클래스 메소드를 만들고 그 안에서 제어기능까지 하며 수정하는게 더 좋다. @classmethod def raise_price(cls,per): if per
클래스에 변수가 있을 경우 class Car(): """ Car class Author : Kim Date : 2019.11.08 사용법 : """ # 클래스 변수(모든 인스턴스가 공유) car_count = 0 def __init__(self,company,detail): self._company = company self._detail = detail self.car_count = 10 Car.car_count +=1 print(car1.car_count) print(car2.car_count) print(car1.__dict__) print(car2.__dict__) print(dir(car1)) 첫번째, 두번째 print 문에서는 0으로 값이 출력된다. 세번째, 네번째 print 문에서는 car_..
module을 상속받을 때 super().__init__()을 하는 이유 socket 모듈을 만들고 GUI 모듈을 만드는데 항상 super().__init__()을 안써서 에러가 난다. QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) port = 8000 class CWidget(QWidget): def __init__(self): super().__init__() self.c = client.ClientSocket(self) 저번에는 AttributeError: cannot assign module before Module.init() call 이 발생하더니 이번에는 RuntimeError: super-class init() of type CW..
가끔 ''' 불라불라 ''' 이렇게 주석으로 되어있는 멘션이 있다. 이거의 사용법은 바로 클래스로 접근해서 __doc__을 사용가능하고 클래스 바로 접근 -> Car.__doc__ 인스턴스 하나 만들어서 car1 = Car(~~~~) car.__doc__ 을 print 찍으면 주석처리 된 문구가 나온다. class Car(): ''' Car class Author : Min Data 2023 ''' print(car1.__doc__) print(Car.__doc__) Car class Author : Min Data 2023 Car class Author : Min Data 2023 클래스의 아이디값과 인스턴스의 아이디값 비교해보자 print(car1 is Car) print(id(car1.__class..
객체 지향 프로그래밍(oop) -> 코드의 재사용, 코드 중복 방지, 유지보수, 대형프로젝트 규모가 큰 프로젝트(프로그램) -> 함수 중심-> 데이터 방대 -> 복잡 클래스 중심 -> 데이터 중심 -> 객체로 관리 클래스 구조 구조 설계 후 재사용성 증가, 코드 반복 최소화, 메소드 활용 class Car(): def __init__(self,company,details): self._company = company self._details = details def __str__(self) -> str: return 'str : {} {}.'.format(self._company,self._details) def __repr__(self) -> str: return 'repr : {} {}'.format..