◇グローバル変数(Global Variable)
a='abcd'
def func():
print('②関数内でアクセス')
for i in range(3):
print(a+'③')
if i%2==0:
print(a+'CDE') #④
else:
print(a+'123') #⑤
print('a'+'<- ①関数外で変数にアクセス')
func() # func()の実行
実行結果)
a<- ①関数外で変数にアクセス
②関数内でアクセス
abcd③
abcdCDE④
##(For Loop内)
abcd③
abcd123⑤
abcd③
abcdCDE④
◇オブジェクトのisinstance() でチェック。
# Variables of different types
i = 1
f = 0.1
s = "Hell"
l = [0, 1, 2]
d = {0:"Zero", 1:"One"}
t = (0, 1, 2)
b = True
n = None
All of the following return
True
:isinstance(i, int)
isinstance(f, float)
isinstance(s, str)
isinstance(l, list)
isinstance(d, dict)
isinstance(t, tuple)
rue and
False
are an instance of bool
, so:isinstance(b, bool)
What about
None
? For that, there is alwaysn is None
0 件のコメント:
コメントを投稿