스페셜 메소드

Andromeda_Galaxy·2024년 7월 7일

사칙 연산 메소드

__add__(self, other)

  • 더하기
  • x + y → x.__add__(y)

__sub__(self, other)

  • 빼기
  • x - y → x.__sub__(y)

__mul__(self, other)

  • 곱하기
  • x * y → x.__mul__(y)

__truediv__(self, other)

  • 나누기
  • x / y → x.__truediv__(y)

불린 메소드

__bool__(self)

  • 불린
  • bool(x) → x.__bool__()

컨테이너 메소드

  • 정해지지 않은 개수의 데이터를 담을 수 있는 객체

__len__(self)

  • 길이
  • len(x) → x.__len__()

__getitem__(self, key)

  • 요소 가져오기
  • x[key] → x.__getitem__(key)

__setitem__(self, key, item)

  • 요소 설정하기
  • x[key] = item → x.__setitem__(key, item)
profile
안녕하세요.

0개의 댓글