データの種類について
2.データの種類について
データの種類は、次の図のように、そのデータの使用目的やアクセス手法等、いくつかの基準により分類されている。
Pythonでは、データの種類(型)により、表示やアクセス方法等プログラム処理が異なるので、変数に格納されたデータの種類(型)をtype()で確認するためのコードを載せておく。
str='abc'#文字列型
print (type (str))#class 'str'
num=5#整数型
print (type (num))#class 'int'
num=3.14#浮動小数点型、実数型
print (type (num))#class 'float'
check_flg = True#ブール型、論理型
check_flg = False
print (type (check_flg))#class 'bool'
date1 = '2021/8/31'#日付型
print (type (date1))#class 'str'
list = ['abc', 6, True]#リスト型、配列型
print (type (list))#class 'list'
tuple =('abc', 6, True)#タプル型
print (type (tuple))#class 'tuple'
dict = {'Key1' : 'Val1', 'Key2' : 'Val2'}#辞書型
print (type (dict))#class 'dict'