Pythonの変数、文字列、整数

開発者のためのPython入門

Jasmin Ludolf

Senior Data Science Content Developer

変数を理解する

  • 情報を格納して再利用する
  • 読みやすく理解しやすい
  • 何度も同じことを入力する必要がない

Jars in a kitchen cupboard

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

データ型

  • 値の種類
    • 数値
    • 文字列
    • 真/偽
  • Pythonはデータ型を自動的に割り当てる

Data types

開発者のためのPython入門

文字列型

  • 文字列: テキスト値
  • 文字、数字、句読点が含まれる

$$

"Hello, world!"
"20-minute pasta recipe"
開発者のためのPython入門

文字列型

  • 文字列: テキスト値
  • 文字、数字、句読点が含まれる
  • シングルまたはダブルクォートを使う
  • アポストロフィを含む語にはダブルクォート
"Chef's secret seasoning"
'Chef's secret seasoning'
開発者のためのPython入門

文字列変数

$$

ingredient_name

$$

  • 小文字と、スペースの代わりにアンダースコアを使う
開発者のためのPython入門

文字列変数

$$

ingredient_name =
開発者のためのPython入門

文字列変数

$$

ingredient_name = "Tomatoes"
開発者のためのPython入門

整数型と変数

  • 整数: 小数点や分数のない数値
  • 引用符は不要

$$

ingredient_quantity = 2
開発者のためのPython入門

変数を表示する

print(ingredient_name)
Tomatoes
print(ingredient_quantity)
2
開発者のためのPython入門

変数を調整する

print(ingredient_quantity)
2

$$

ingredient_quantity = 1

print(ingredient_quantity)
1
開発者のためのPython入門

練習してみましょう!

開発者のためのPython入門

Preparing Video For Download...