Notice
Recent Posts
Recent Comments
Link
목록클래스 변수 (1)
초보 개발자
파이썬 인스턴스 변수, 클래스 변수, 인스턴스 메서드, 클래스 메서드
class Person(): people_cnt = 0 def __init(self,name): self.name = name Person.people_cnt += 1 @classmethod def get_cnt(cls): print(cls.people_cnt) def get_cnt2() print(Person.people_cnt) def get_name(self): print(self.name) kim = Person('kim') lee = Person('Lee') 이러한 클래스가 있다고 가정해보자 기본적으로 people_cnt라는 클래스 변수를 0으로 지정해두었다. 그리고 객체가 생성될 때 인스턴스 메소드 __init__이 실행이된다. self.name(인스턴스 변수)에 name이들어가고 Person..
Python/이것 저것
2021. 12. 26. 17:43