Python में ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग
Alex Yarosh
Content Quality Analyst @ DataCamp


$$\Large{\text{Object = state + behavior}}$$

$$\text{\textbf{Encapsulation} - डेटा और उस पर काम करने वाला कोड साथ बाँधना}$$


type() से क्लास देखेंimport numpy as np
a = np.array([1,2,3,4])
print(type(a))
numpy.ndarray
| Object | Class |
|---|---|
5 |
int |
"Hello" |
str |
pd.DataFrame() |
DataFrame |
np.mean |
function |
| ... | ... |
import numpy as np a = np.array([1,2,3,4])# shape attribute a.shape
(4,)
obj. उपयोग करेंimport numpy as np a = np.array([1,2,3,4])# reshape method a.reshape(2,2)
array([[1, 2],
[3, 4]])
attribute ↔ variables ↔ obj.my_attribute,
method ↔ function() ↔ obj.my_method().
import numpy as np
a = np.array([1,2,3,4])
dir(a) # <--- सभी attributes और methods की सूची
['T',
'__abs__',
...
'trace',
'transpose',
'var',
'view']
Python में ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग