@classmethod 완벽 이해

이해가 잘 안돼서 찾아보다가 발견한 동영상 입니다.

몇번 보니 이해가 조금(?) 되네요. (머리가 나빠서요 ㅎ)

https://youtu.be/MP-MXkQPrEc

[code]

class Member():
    _ins = []

    def __init__(self, name, height, weight, fat):
        self.name = name
        self.height = height
        self.weight = weight
        self.fat = fat

        self.add_instance(self)

    @classmethod
    def add_instance(cls, ins):
        cls._ins.append(ins)

a = Member("kim", 180, 77, 24)
b = Member("Ihm", 170, 71, 16)
c = Member("Choi", 160, 51, 23)
d = Member("Park", 170, 63, 20)

height_mean = sum([m.height for m in Member._ins]) / len(Member._ins)
print(f"height_mean = {height_mean}")

[/code]

|

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

파이썬 게시판 만들기

+
번호 제목 글쓴이 날짜 조회
121 1년 전 조회 722
120 1년 전 조회 537
119 2년 전 조회 547
118 2년 전 조회 534
117 2년 전 조회 761
116 2년 전 조회 591
115 2년 전 조회 965
114 2년 전 조회 730
113 2년 전 조회 694
112 2년 전 조회 1,010
111 2년 전 조회 904
110 2년 전 조회 760
109 3년 전 조회 1,008
108 3년 전 조회 1,111
107 3년 전 조회 1,160
106 3년 전 조회 1,140
105 3년 전 조회 1,083
104 4년 전 조회 1,348
103 4년 전 조회 1,298
102 4년 전 조회 1,513
101 4년 전 조회 1,266
100 4년 전 조회 2,546
99 4년 전 조회 1,252
98 4년 전 조회 1,085
97 4년 전 조회 1,244
96 4년 전 조회 1,646
95 5년 전 조회 1,626
94 5년 전 조회 1,402
93 5년 전 조회 1,522
92 5년 전 조회 1,518
🐛 버그신고