変数のデータ型

ファイナンスのためのPython入門

Adina Howe

Professor

Pythonのデータ型

変数の型
文字列 'hello world'
整数 40
浮動小数 3.1417
ブール値 True / False
ファイナンスのためのPython入門

変数の型

変数の型 略記
文字列 'Tuesday' str
整数 40 int
浮動小数 3.1417 float
ブール値 True / False bool
ファイナンスのためのPython入門

変数のデータ型を調べる: type()

型を調べるには関数 type() を使います:

type(variable_name)
pe_ratio = 40
print(type(pe_ratio))
<class 'int'>
ファイナンスのためのPython入門

変数の操作

x = 5
print(x * 3)
15
print(x + 3)
8
y = 'stock'
print(y * 3)
'stockstockstock'
print(y + 3)
TypeError: must be str, not int
ファイナンスのためのPython入門

変数型の変換

pi = 3.14159
print(type(pi))
<class 'float'>
pi_string = str(pi)
print(type(pi_string))
<class 'str'>
print('I love to eat ' + pi_string + '!')
I love to eat 3.14159!
ファイナンスのためのPython入門

Passons à la pratique !

ファイナンスのためのPython入門

Preparing Video For Download...