/* 一 */ >>> class T (): a = 0 b = a >>> T.b 0 >>> del T /* 二 */ >>> class T (): a = 0 b = T.a Traceback (most recent call last): File "<pyshell#9>", line 1, in <module> class T (): File "<pyshell#9>", line 3, in T b = T.a NameError: name ‘T‘ is not defined /* 三 */ >>> class T (): def a (self): print (‘a‘) def ab (self): a (self) print (‘b‘) >>> T.ab (‘test‘) Traceback (most recent call last): File "<pyshell#19>", line 1, in <module> T.ab (‘test‘) File "<pyshell#18>", line 5, in ab a (self) NameError: name ‘a‘ is not defined >>> del T /* 四 */ >>> class T (): def a (self): print (‘a‘) def ab (self): T.a (self) print (‘b‘) >>> T.ab (‘test‘) a b >>> del T /* 五 */ >>> class T (): a = 0 def pa (self): print (a) >>> T.pa (‘test‘) Traceback (most recent call last): File "<pyshell#27>", line 1, in <module> T.pa (‘test‘) File "<pyshell#25>", line 4, in pa print (a) NameError: name ‘a‘ is not defined >>> del T /* 六 */ >>> class T (): a = 0 def pa (self): print (T.a) >>> T.pa (‘test‘) 0 >>> del T >>>
--date-- 2015-05-31
时间: 2024-09-29 18:01:58