Objectgeoriënteerd programmeren in Python
Alex Yarosh
Content Quality Analyst @ DataCamp


$$\Large{\text{Object = toestand + gedrag}}$$

$$\text{\textbf{Encapsulatie} - bundelen van data met code die erop werkt}$$


type() om de klasse te vindenimport numpy as np
a = np.array([1,2,3,4])
print(type(a))
numpy.ndarray
| Object | Klasse |
|---|---|
5 |
int |
"Hallo" |
str |
pd.DataFrame() |
DataFrame |
np.mean |
functie |
| ... | ... |
import numpy as np a = np.array([1,2,3,4])# vorm attribuut a.shape
(4,)
obj. om toegang te krijgen tot attributen en methodenimport numpy as np a = np.array([1,2,3,4])# herindelingsmethode a.reshape(2,2)
array([[1, 2],
[3, 4]])
attribuut ↔ variabelen ↔ obj.mijn_attribuut,
methode ↔ functie() ↔ obj.mijn_methode().
import numpy as np
a = np.array([1,2,3,4])
dir(a) # <--- lijst alle attributen en methoden
['T',
'__abs__',
...
'trace',
'transpose',
'var',
'view']
Objectgeoriënteerd programmeren in Python