変数の作成

Pythonで始めるデータサイエンス入門

Hillary Green-Lerman

Lead Data Scientist, Looker

迷子の子犬届の作成

迷子の子犬届

name = "Bayes"
height = 24
weight = 75.5
Pythonで始めるデータサイエンス入門

変数名のルール

  • 文字で開始(通常は小文字)
  • 先頭以降は文字・数字・アンダースコア可
  • 空白・記号は不可
  • 大文字小文字は区別(my_varMY_VAR は別)
# 有効な変数名
bayes_weight
b
bayes42
# 無効な変数名
bayes-height
bayes!
42bayes
Pythonで始めるデータサイエンス入門

エラーメッセージ

bayes-height = 3
File "<stdin>", line 1
    bayes-height = 3
                   ^
SyntaxError: can't assign to operator
Pythonで始めるデータサイエンス入門

浮動小数点数と文字列

  • float: 整数または小数を表す

    height = 24
    weight = 75.5
    
  • string: 文字列(文字・数字・空白・記号を含められる)を表す

    name = 'Bayes'
    breed = "Golden Retriever"
    
Pythonで始めるデータサイエンス入門

文字列のよくあるミス

  • 引用符なしだと NameError が発生します。
owner = DataCamp
File "<stdin>", line 1, in <module>
    owner = DataCamp
NameError: name 'DataCamp' is not defined
  • 引用符の種類が混在すると SyntaxError になります。
fur_color = "blonde'
File "<stdin>", line 1
    fur_color = "blonde'
                       ^
SyntaxError: EOL while scanning string literal
Pythonで始めるデータサイエンス入門

変数の表示

name = "Bayes"
height = 24
weight = 75

print(height)
24
Pythonで始めるデータサイエンス入門

Passons à la pratique !

Pythonで始めるデータサイエンス入門

Preparing Video For Download...