Re: [問題] 類別問題
※ 引述《MicroPtt (Mission Start)》之銘言:
: class aa(object):
: def bb(self)
: self.cc
: 請問要怎麼把 self.cc 這行弄到外面當一個[全域變數]
: 我是寫 aa.bb.cc or aa.cc
: 都會說aa裡面沒有cc的 attribute
: 類別學不好= = 如果觀念錯請多包含
class aa(object):
cc = 'hi cc'
def bb(self):
self.dd = 'hi dd'
global ee
ee = 'hi ee'
a = aa()
a.bb()
print a.dd
print aa.cc
print ee
執行後:
$ ./test.py
hi dd
hi cc
hi ee
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.129.77.13
→
07/10 15:56, , 1F
07/10 15:56, 1F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章