Variabili e tipi

Introduzione a Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Variabile

  • Nome specifico, con distinzione tra maiuscole e minuscole

  • Richiamare il valore tramite il nome della variabile

  • 1,79 m - 68,7 kg

height = 1.79
weight = 68.7

height
1.79
Introduzione a Python

Calcola il BMI

height = 1.79
weight = 68.7

height
1.79

$$ \text{BMI} = \frac{\text{peso}}{\text{altezza}^2} $$

68.7 / 1.79 ** 2
21.4413
weight / height ** 2
21.4413
bmi = weight / height ** 2
bmi
21.4413
Introduzione a Python

Riproducibilità

height = 1.79
weight = 68.7
bmi = weight / height ** 2
print(bmi)
21.4413
Introduzione a Python

Riproducibilità

height = 1.79
weight = 74.2 # <-
bmi = weight / height ** 2
print(bmi)
23.1578
Introduzione a Python

Tipi Python

type(bmi)
float
day_of_week = 5
type(day_of_week)
int
Introduzione a Python

Tipi Python (2)

x = "body mass index"
y = 'this works too'

type(y)
str
z = True
type(z)
bool
Introduzione a Python

Tipi Python (3)

2 + 3
5
'ab' + 'cd'
'abcd'
  • Tipo diverso = comportamento diverso!
Introduzione a Python

Passiamo alla pratica!

Introduzione a Python

Preparing Video For Download...