파이썬 객체 지향 프로그래밍 - Attributes & Methods
Page content
	
1줄 요약
- Attributes & Methods의 차이점에 대해 이해한다.
 
개요
- Object = State + Behavior
- 예) Email, Phone Number, 배송상태
 
 - Class는 일종의 가이드라인을 의미
 - 파이썬 내의 모든 객체는 일종으 클래스임
 
| Object | Class | 
|---|---|
| 7 | int | 
| “Hello” | str | 
| pd.DataFrame() | DataFrame | 
- 해당 클래스를 찾기 위해 
type( )를 사용함. 
import numpy as np
temp = np.array([1, 2, 3])
print(type(temp))
<class 'numpy.ndarray'>
State + Behavior

- 그렇다면, State를 지칭하는 파이썬 문법은 무엇인가?
- 파이썬에서는 이를 
Attributes라고 부른다. 
 - 파이썬에서는 이를 
 - 또한, Behavior를 지칭하는 파이썬 문법은 무엇인가?
- 파이썬에서는 이를 
Methods라고 부른다. 
 - 파이썬에서는 이를 
 - 먼저 Attributes 문법을 확인해본다.
 
# shape attribute
temp.shape
(3,)
- 이번에는 Methods 문법을 확인해본다.
 
# reshpae method
temp.reshape(3, 1)
array([[1],
       [2],
       [3]])
소결
- Object = Attributes + Methods
- attribute <-> variables <-> obj.my_attribute,
 - attribute <-> function() <-> obj.my_method().
 
 - dir() 해당 객체의 모든 attributes, methods를 보여줌
 
dir(temp)
['T',
 '__abs__',
 '__add__',
 '__and__',
 '__array__',
 '__array_finalize__',
 '__array_function__',
 '__array_interface__',
 '__array_prepare__',
 '__array_priority__',
 '__array_struct__',
 '__array_ufunc__',
 '__array_wrap__',
 '__bool__',
 '__class__',
 '__complex__',
 '__contains__',
 '__copy__',
 '__deepcopy__',
 '__delattr__',
 '__delitem__',
 '__dir__',
 '__divmod__',
 '__doc__',
 '__eq__',
 '__float__',
 '__floordiv__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__gt__',
 '__hash__',
 '__iadd__',
 '__iand__',
 '__ifloordiv__',
 '__ilshift__',
 '__imatmul__',
 '__imod__',
 '__imul__',
 '__index__',
 '__init__',
 '__init_subclass__',
 '__int__',
 '__invert__',
 '__ior__',
 '__ipow__',
 '__irshift__',
 '__isub__',
 '__iter__',
 '__itruediv__',
 '__ixor__',
 '__le__',
 '__len__',
 '__lshift__',
 '__lt__',
 '__matmul__',
 '__mod__',
 '__mul__',
 '__ne__',
 '__neg__',
 '__new__',
 '__or__',
 '__pos__',
 '__pow__',
 '__radd__',
 '__rand__',
 '__rdivmod__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__rfloordiv__',
 '__rlshift__',
 '__rmatmul__',
 '__rmod__',
 '__rmul__',
 '__ror__',
 '__rpow__',
 '__rrshift__',
 '__rshift__',
 '__rsub__',
 '__rtruediv__',
 '__rxor__',
 '__setattr__',
 '__setitem__',
 '__setstate__',
 '__sizeof__',
 '__str__',
 '__sub__',
 '__subclasshook__',
 '__truediv__',
 '__xor__',
 'all',
 'any',
 'argmax',
 'argmin',
 'argpartition',
 'argsort',
 'astype',
 'base',
 'byteswap',
 'choose',
 'clip',
 'compress',
 'conj',
 'conjugate',
 'copy',
 'ctypes',
 'cumprod',
 'cumsum',
 'data',
 'diagonal',
 'dot',
 'dtype',
 'dump',
 'dumps',
 'fill',
 'flags',
 'flat',
 'flatten',
 'getfield',
 'imag',
 'item',
 'itemset',
 'itemsize',
 'max',
 'mean',
 'min',
 'nbytes',
 'ndim',
 'newbyteorder',
 'nonzero',
 'partition',
 'prod',
 'ptp',
 'put',
 'ravel',
 'real',
 'repeat',
 'reshape',
 'resize',
 'round',
 'searchsorted',
 'setfield',
 'setflags',
 'shape',
 'size',
 'sort',
 'squeeze',
 'std',
 'strides',
 'sum',
 'swapaxes',
 'take',
 'tobytes',
 'tofile',
 'tolist',
 'tostring',
 'trace',
 'transpose',
 'var',
 'view']
References
- Object-Oriented Programming in Python Retrieved from https://www.datacamp.com/courses/object-oriented-programming-in-python