Python 객체 지향 프로그래밍 입문
George Boorman
Curriculum Manager, DataCamp
| 용어 | 정의 |
|---|---|
| 클래스 | 객체를 만드는 청사진/템플릿 |
| 객체 | 데이터와 _기능_의 조합; 클래스의 인스턴스 |
| 용어 | 정의 |
|---|---|
| 클래스 | 객체를 만드는 청사진/템플릿 |
| 객체 | 데이터와 _기능_의 조합; 클래스의 인스턴스 |
| 상태 | 객체에 연관된 데이터, 속성으로 지정 |
| 동작 | 객체의 _기능_, 메서드로 정의 |
| 연산자 | 메서드 |
|---|---|
== |
__eq__() |
!= |
__ne__() |
>= |
__ge__() |
<= |
__le__() |
> |
__gt__() |
< |
__lt__() |
__str__()print(obj), str(obj)print([1,2,3])
[1 2 3]
str([1,2,3])
'[1, 2, 3]'
__repr__()repr(obj), 콘솔 출력repr([1,2,3])
[1,2,3]
[1,2,3]
[1,2,3]
print()의 폴백class BalanceError(Exception): passclass Customer: def __init__(self, name, balance): if balance < 0 : raise BalanceError("Balance has to be non-negative!") else: self.name, self.balance = name, balance# Use try-except to catch errors try: cust = Customer("Larry Torres", -100) except BalanceError: cust = Customer("Larry Torres", 0)
Python 객체 지향 프로그래밍 입문