1
1. Ce este o variabila?
O variabila este un "container" care stocheaza o valoare. Are un nume si un tip de date.
📦
varsta
15
2
2. Tipuri de date principale
| Tip | Python | C++ | Exemplu |
|---|---|---|---|
| Intreg | int | int | 42, -7, 0 |
| Real | float | float/double | 3.14, -2.5 |
| Text | str | string | "Hello" |
| Logic | bool | bool | True/False |
3
3. Declarare si initializare
# Python - tipul se deduce automat varsta = 15 nume = "Maria" medie = 9.75 esteMajor = False # Afisare print(varsta) # 15 print(nume) # Maria print(type(varsta)) # <class 'int'>
// C++ - tipul trebuie declarat int varsta = 15; string nume = "Maria"; double medie = 9.75; bool esteMajor = false; // Afisare cout << varsta << endl; // 15 cout << nume << endl; // Maria
4
4. Diferente Python vs C++
- Python: tipul se deduce automat (dynamic typing)
- C++: tipul trebuie declarat explicit (static typing)
- Python: True/False cu majuscula
- C++: true/false cu minuscula + ; la final