主なデータ型

開発者のためのPython入門

Jasmin Ludolf

Senior Data Science Content Developer

10進数データ型

  • 整数: 小数点や分数のない数値

$$

  • 浮動小数点数: 小数を含む数値(例: 1.5)
  • 引用符は不要

$$

$$

new_ingredient_quantity = 1.5
開発者のためのPython入門

ブール値型

$$

  • ブール値: 真偽
  • はい/いいえ情報の格納に最適
  • 大文字にする
  • 引用符なし

$$

is_in_stock = True
is_in_stock = False
開発者のためのPython入門

type関数

  • データ型
    • 文字列
    • 整数
    • 浮動小数点数
    • ブール値
type()
  • データ型を示す
開発者のためのPython入門

type関数

文字列

ingredient_name = "tomatoes"

print(type(ingredient_name))
<class 'str'>

整数

ingredient_quantity = 2

print(type(ingredient_quantity))
<class 'int'>

浮動小数点数

new_ingredient_quantity = 1.5

print(type(new_ingredient_quantity))
<class 'float'>

ブール値

is_in_stock = True

print(type(is_in_stock))
<class 'bool'>
開発者のためのPython入門

データ型の理解

  • コードの動作や意図を理解する
  • type() を使用して型を識別する
  • 実行できる操作を確認する

Person working with code on multiple screens

1 画像提供: wutzkoh
開発者のためのPython入門

演算子

  • 演算子と呼ばれる記号を使って計算を行う

算術演算子:

  • + 加算
  • - 減算
  • *乗算
  • / 除算

数値:

  • 通常の数学と同様に動作する
    print(2 + 1.5)
    
3.5

文字列:

  • +* のみが動作する

"Hi" + "There" = "HiThere"

"Hi" * 3 = "HiHiHi"

開発者のためのPython入門

練習しましょう!

開発者のためのPython入門

Preparing Video For Download...