리자

@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년 전 조회 732
2년 전 조회 547
2년 전 조회 555
2년 전 조회 546
2년 전 조회 772
2년 전 조회 602
2년 전 조회 979
2년 전 조회 742
2년 전 조회 705
2년 전 조회 1,025
2년 전 조회 918
2년 전 조회 771
3년 전 조회 1,020
3년 전 조회 1,126
3년 전 조회 1,174
3년 전 조회 1,156
3년 전 조회 1,096
4년 전 조회 1,359
4년 전 조회 1,305
4년 전 조회 1,524
4년 전 조회 1,276
4년 전 조회 2,564
4년 전 조회 1,264
4년 전 조회 1,097
4년 전 조회 1,254
4년 전 조회 1,660
5년 전 조회 1,640
5년 전 조회 1,416
5년 전 조회 1,539
5년 전 조회 1,531
🐛 버그신고