전역변수와 클래스 내부 지역변수 사용

Eunjung-Cho·2021년 6월 5일
0

1. 전역변수로 쓸 경우

import pygame

DISPLAY_SIZE = (640, 480)

class SimpleGame:
    def __init__(self, b_color = 'white'):
        pygame.init()
        
        self.screen = pygame.display.set_mode(DISPLAY_SIZE)

클래스 내부에서 변수이름만 써도 된다.

2. 클래스 내부 지역변수로 쓸 경우

class SimpleGame:
    DISPLAY_SIZE = (640, 480)
    def __init__(self, b_color = 'white'):
        pygame.init()

        self.screen = pygame.display.set_mode(SimpleGame.DISPLAY_SIZE)

클래스이름.변수이름( = SimpleGame.DISPLAY_SIZE) 이렇게 써야 한다.

profile
IT컨설팅 데이터 분석가

0개의 댓글