리자

@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]

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

파이썬 게시판 만들기

+
제목 글쓴이 날짜 조회
1년 전 조회 729
2년 전 조회 545
2년 전 조회 553
2년 전 조회 544
2년 전 조회 771
2년 전 조회 600
2년 전 조회 976
2년 전 조회 742
2년 전 조회 703
2년 전 조회 1,024
2년 전 조회 915
2년 전 조회 769
3년 전 조회 1,018
3년 전 조회 1,124
3년 전 조회 1,171
3년 전 조회 1,151
3년 전 조회 1,095
4년 전 조회 1,357
4년 전 조회 1,304
4년 전 조회 1,522
4년 전 조회 1,275
4년 전 조회 2,562
4년 전 조회 1,261
4년 전 조회 1,096
4년 전 조회 1,253
4년 전 조회 1,658
5년 전 조회 1,638
5년 전 조회 1,412
5년 전 조회 1,536
5년 전 조회 1,529
🐛 버그신고