python 單底線和雙底線,python底線

來源:互聯網
上載者:User

python 單底線和雙底線,python底線

 1 underline.py 2 __all__ = ['_underline_variable', '__underline_variable', '_underline_func', 3            '__underline_func', '_underline_class', '__underline_class'] 4  5  6 _underline_variable = 100 7 __underline_variable = 200 8  9 10 def _underline_func():11     pass12 13 def __underline_func():14     pass15 16 class _underline_class():17     pass18 19 class __underline_class():20     pass21 22 23 class Base():24     def _underline(self):25         pass26 27     def __underline(self):  # 私人28         pass29 30 31 class Derived(Base):32     pass33 34 if __name__ == '__main__':35     base = Base()36     base._underline()37     #base.__underline()38     base._Base__underline()39     40     derived = Derived()41     derived._underline()42     #derived._Derived__underline()43     derived._Base__underline()
 1 test.py 2 # 1 用import方式匯入 3 import underline 4  5 print(underline._underline_variable) 6 print(underline.__underline_variable) 7 underline._underline_func() 8 underline.__underline_func() 9 test1 = underline._underline_class()10 test2 = underline.__underline_class()11 12 print('*' * 20)13 14 15 # 2 沒有定義__all__屬性,用from ... import *方式匯入16 #from underline import *17 #print(_underline_variable)18 #print(__underline_variable)19 #_underline_func()20 #__underline_func()21 #test1 = _underline_class()22 #test2 = __underline_class()23 24 25 # 3 定義__all__屬性,用from ... import *方式匯入26 from underline import *27 print(_underline_variable)28 print(__underline_variable)29 _underline_func()30 __underline_func()31 test1 = _underline_class()32 test2 = __underline_class()

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.