変数と型

Python 入門

Hugo Bowne-Anderson

Data Scientist at DataCamp

変数

  • 大文字と小文字を区別する、特定の名前

  • 変数名を使って値を呼び出す

  • 1.79 m - 68.7 kg

height = 1.79
weight = 68.7

height
1.79
Python 入門

BMIを計算する

height = 1.79
weight = 68.7

height
1.79

$$ \text{BMI} = \frac{\text{weight}}{\text{height}^2} $$

68.7 / 1.79 ** 2
21.4413
weight / height ** 2
21.4413
bmi = weight / height ** 2
bmi
21.4413
Python 入門

再現性

height = 1.79
weight = 68.7
bmi = weight / height ** 2
print(bmi)
21.4413
Python 入門

再現性

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

Pythonの型

type(bmi)
float
day_of_week = 5
type(day_of_week)
int
Python 入門

Pythonの型(2)

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

type(y)
str
z = True
type(z)
bool
Python 入門

Pythonの型(3)

2 + 3
5
'ab' + 'cd'
'abcd'
  • 異なる型 = 異なる動作!
Python 入門

練習しましょう!

Python 入門

Preparing Video For Download...