Introducere în Programarea Orientată pe Obiecte în Python
George Boorman
Curriculum Manager, DataCamp



$$\Large{\text{Obiect = date + funcționalitate}}$$

Stare - datele unui obiect
Comportament - funcționalitatea unui obiect
| Obiect | Tip |
|---|---|
5 |
int |
"Hello" |
str |
pd.DataFrame() |
DataFrame |
sum() |
function |
| ... | ... |


lists este o clasă[1, 2, 3, 4, 5].append()type() pentru a afla clasatype([1, 2, 3, 4, 5])
<class 'list'>
import pandas as pd df = pd.DataFrame({"a": [1,2,3], "b": [4,5,6]})# shape attribute df.shape
(3, 2)
obj. pentru a accesa atribute și metodeimport pandas as pd df = pd.DataFrame({"a": [1,2,3], "b": [4,5,6]})# head method df.head()
a b
0 1 4
1 2 5
2 3 6
# Display attributes and methods
dir([1, 2, 3, 4])
['__add__',
'__class__',
'__contains__',
'__delattr__',
...
'pop',
'remove',
'reverse',
'sort']
# Display attributes and methods
dir(list)
['__add__',
'__class__',
'__contains__',
'__delattr__',
...
'pop',
'remove',
'reverse',
'sort']
| Termen | Definiție |
|---|---|
| Clasă | Un șablon/model folosit pentru a construi obiecte |
| Obiect | O combinație de date și funcționalitate; O instanță a unei clase |
| Stare | Date asociate unui obiect, atribuite prin atribute |
| Comportament | Funcționalitatea unui obiect, definită prin metode |
Introducere în Programarea Orientată pe Obiecte în Python