Objektorientierte Programmierung in Python
Alex Yarosh
Content Quality Analyst @ DataCamp


$$\Large{\text{Objekt = Zustand + Verhalten}}$$

$$\text{\textbf{Kapselung} - Daten mit dem Code bündeln, der darauf arbeitet}$$


type() die Klasse herausfindenimport numpy as np
a = np.array([1,2,3,4])
print(type(a))
numpy.ndarray
| Objekt | Klasse |
|---|---|
5 |
int |
"Hallo" |
str |
pd.DataFrame() |
DataFrame |
np.mean |
function |
| ... | ... |
import numpy as np a = np.array([1,2,3,4])# shape-Attribut a.shape
(4,)
obj. auf Attribute und Methoden zugreifenimport numpy as np a = np.array([1,2,3,4])# reshape-Methode a.reshape(2,2)
array([[1, 2],
[3, 4]])
Attribut ↔ Variablen ↔ obj.mein_attribut,
Methode ↔ Funktion() ↔ obj.meine_methode().
import numpy as np
a = np.array([1,2,3,4])
dir(a) # <--- listet alle Attribute und Methoden auf
['T',
'__abs__',
...
'trace',
'transpose',
'var',
'view']
Objektorientierte Programmierung in Python