리자

@classmethod 완벽 이해

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

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

 

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

 

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]

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
24-02-08 조회 1,048
24-01-19 조회 868
23-12-24 조회 858
23-08-03 조회 907
23-07-27 조회 1,130
23-07-27 조회 980
23-07-18 조회 1,393
23-07-12 조회 1,097
23-07-12 조회 1,098
23-07-07 조회 1,411
23-06-30 조회 1,335
23-06-28 조회 1,157
22-09-04 조회 1,476
22-08-17 조회 1,503
22-07-22 조회 1,517
22-05-24 조회 1,538
22-02-02 조회 1,467
21-12-29 조회 1,745
21-12-24 조회 1,666
21-12-15 조회 1,902
21-05-29 조회 1,664
21-05-01 조회 2,952
21-03-16 조회 1,658
21-03-16 조회 1,472
21-03-01 조회 1,589
21-02-16 조회 2,061
21-01-02 조회 2,061
20-12-14 조회 1,772
20-12-02 조회 1,963
20-12-02 조회 1,973