Variabelen en typen

Introductie tot Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Variabele

  • Specifieke, hoofdlettergevoelige naam

  • Roep de waarde op via de naam van de variabele.

  • 1,79 m - 68,7 kg

height = 1.79
weight = 68.7

height
1.79
Introductie tot Python

Bereken BMI

height = 1.79
weight = 68.7

height
1.79

$$ \text{BMI} = \frac{\text{gewicht}}{\text{lengte}^2} $$

68.7 / 1.79 ** 2
21.4413
weight / height ** 2
21.4413
bmi = weight / height ** 2
bmi
21.4413
Introductie tot Python

Reproduceerbaarheid

height = 1.79
weight = 68.7
bmi = weight / height ** 2
print(bmi)
21.4413
Introductie tot Python

Reproduceerbaarheid

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

Python-typen

type(bmi)
float
day_of_week = 5
type(day_of_week)
int
Introductie tot Python

Python-typen (2)

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

type(y)
str
z = True
type(z)
bool
Introductie tot Python

Python-typen (3)

2 + 3
5
'ab' + 'cd'
'abcd'
  • Ander type = ander gedrag!
Introductie tot Python

Laten we oefenen!

Introductie tot Python

Preparing Video For Download...