파이썬[Python]: 내장함수 - __lt__ 메서드
파이썬(Phthon): 내장함수 - __lt__ 메서드(method)
/// 설명
self 와 other 를 비교합니다.(self < other: True)
other 은 비교할 객체입니다.
참고: __le__(), __eq__(), __ne__(), __gt__(), __ge__()
※ 형식
object.__lt__(self, other)
reference
https://docs.python.org/3/reference/datamodel.html
other 은 비교할 객체입니다.
참고: __le__(), __eq__(), __ne__(), __gt__(), __ge__()
※ 형식
object.__lt__(self, other)
reference
https://docs.python.org/3/reference/datamodel.html
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class A: def __init__(self, a): self.a = a def __lt__(self, other): return self.a < other.a print(A(1).__lt__(A(2))) # True a = A(1) b = A(2) print(a < b) # True if a < b: print('a is less than b') else: print('b is less than a') # a is less than b | cs |
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기