리자

@classmethod 완벽 이해

· 2023-07-12 (수) 10:14:14 · 1086

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

 

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

 

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]

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
19-11-19 조회 1,252
19-11-08 조회 1,299
19-11-07 조회 1,298
19-11-07 조회 1,435
19-10-30 조회 1,146
19-10-25 조회 1,064
19-10-24 조회 1,122
19-10-24 조회 1,378
19-09-20 조회 5,609
19-08-07 조회 1,492
19-06-11 조회 1,115
19-06-09 조회 2,305
19-06-05 조회 1,996
19-06-04 조회 1,383
19-06-04 조회 1,754
19-06-03 조회 1,504
19-06-03 조회 1,289
19-06-03 조회 1,260
19-06-03 조회 3,719
19-06-02 조회 1,675
19-06-01 조회 1,955
19-06-01 조회 1,730
19-06-01 조회 1,734
19-06-01 조회 1,883
19-06-01 조회 1,959
19-05-31 조회 1,932
19-05-31 조회 2,383
19-05-31 조회 2,032
19-05-31 조회 1,648
19-05-31 조회 2,092