클래스변수
-
Python Class - 2Programming/python 2021. 6. 24. 22:17
클래스 변수 와 인스턴스 변수 Swift에도 존재하지만, 클래스 변수 : 클래스 전체에서 공유하는 변수 인스턴스 변수 : 생성된 객체 안에서만 공유되는 변수 # 클래스 변수와 인스턴스 변수 # 클래스 변수는 모든 클래스에서 공유, 인스턴스 변수는 생성후 사용 가능 class Student(): # 클래스 변수 student_count = 0 def __init__(self, name, number): # 인스턴스 변수 self._name = name self._number = number Student.student_count += 1 def __str__(self): return 'str {}'.format(self._name) def __repr__(self): return 'repr {}'.form..