본문 바로가기
개발일지/Python

파이썬 [class 기초원리] - 정리판2 class(클래스) 내용(객체 속성) 변경

by 개발에정착하고싶다 2022. 5. 20.
320x100
# 객체 속성 변경

class NewGenerationPC:

    def __init__(self, name, cpu, memory, ssd):
        # 여기서 self.뒤에 나오는 name은 class가 생성될때 입력받은 속성이다.
        # class 생성이란, class 제작이 완료된 이후에 car1 = Car(1000,'white')이런걸 의미한다.
        # 그리고 뒤에나오는 name은 init에서 받은 name이라고는 하는데 사실상 이론상으로 봤을때
        # 별도인거지, 실질적으론 어떻게 구분이되는지 아직 잘 모르겠다.
        # 암튼 init 뒤에 오는 속성값은 "매개변수"라고 부른다.
        self.name = name
        self.cpu = cpu
        self.memory = memory
        self.ssd = ssd

    def deExcel(self):
        print('EXCEL RUN!!')


    def doPhotoshop(self):
        print('PHOTOSHOP RUN!!')

    def printPCInfo(self):
        print(f'self.name: {self.name}')
        print(f'self.cpu: {self.cpu}')
        print(f'self.memory: {self.memory}')
        print(f'self.ssd: {self.ssd}')


pc1 = NewGenerationPC('myPC', 'i5','16G','256G')
pc1.printPCInfo()

friendPC = NewGenerationPC('friendPC','i9','32G','512G')
friendPC.printPCInfo()

# pc1를 업그레이드 하는 과정
# pc1에 대해서 속성 변경하는 과정
pc1.cpu = 'i9'
pc1.memory = '64G'
pc1.ssd = '1TB'

pc1.printPCInfo()
300x250