리자

@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년 전 조회 733
2년 전 조회 550
2년 전 조회 560
2년 전 조회 547
2년 전 조회 776
2년 전 조회 604
2년 전 조회 983
2년 전 조회 747
2년 전 조회 708
2년 전 조회 1,027
2년 전 조회 918
2년 전 조회 774
3년 전 조회 1,022
3년 전 조회 1,127
3년 전 조회 1,177
3년 전 조회 1,159
3년 전 조회 1,099
4년 전 조회 1,362
4년 전 조회 1,308
4년 전 조회 1,527
4년 전 조회 1,278
4년 전 조회 2,569
4년 전 조회 1,267
4년 전 조회 1,101
4년 전 조회 1,256
4년 전 조회 1,664
5년 전 조회 1,642
5년 전 조회 1,417
5년 전 조회 1,544
5년 전 조회 1,534
🐛 버그신고