pf-15. データの種類
Python 入門)
URL: https://www.kkaneko.jp/pro/pf/index.html
1
金子邦彦
データの種類
文字データ
数値データ
その他
2
Python の主なデータの種類
3
データの種類
クラス名
Python
プログラムでの書き方
整数
int
10
Decimal
import decimal
decimal.Decimal
(10)
浮動小数
float
1.23
complex
文字列
str
"Hello, World
\n"
true/false
bool
True
日時
datetime.datetime
import datetime as dt
dt.datetime
(2022, 12, 1, 1, 23, 45)
リスト
List
[1, 2, 3]
レンジ
range
range(1, 4)
辞書
dict
{1: "orange", 2: "apple", 3: "apple"}
numpy
配列
numpy.ndarray
import
numpy as np
np.array
([1, 2, 3])
Python の主なキーワード
print 表示
type 型名(クラス名)の取得
if, else 条件分岐
for, while 繰り返し
def 関数定義
return 関数の評価値
class クラス定義
__init__ オブジェクトの生成(コンストラクタ)
self クラス定義内で自オブジェクトへアクセス
type オブジェクトのクラス名
dir オブジェクトのメソッド名と属性名
vars オブジェクトの属性名と値
super 親クラス(スーパークラス) 4
Python でのクラスの取得
Python では,type を用いてオブジェクトのクラス
名を取得できる
5
Python でのメソッド名,属性名の取得
Python では,dir を用いて,オブジェクトのメソッ
ド名,属性名など取得できる
6
print(dir(a))
Python でのメソッド名,属性名の取得
Python では,var を用いて,オブジェクトの属性名
と属性値取得できる
7
print(vars(a))
メソッド名,メソッドの実行結果として得られる
オブジェクトのクラスの表示
obj = 100
for x in dir(obj): print(x, ':', type(eval("obj."+x)))
8