name ='bossen'
_name ='neo'defget_name():print('name is', name)def_get_name():print('name is', _name)
进入python的交互模式:
>>>from examples import*>>> name
'bossen'>>> _name
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
NameError: name '_name'isnot defined
>>> get_name()
name is bossen
>>> _get_name()
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
NameError: name '_get_name'isnot defined
>>>classEmployee:... _department ='SQA'... __title ='employee'... @staticmethod...def_test_protected():...return'this is a protected method'... @staticmethod...def__test_private():...return'this is a private method'...>>> e = Employee()>>> e._department
'SQA'>>> e.__title
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
AttributeError:'Employee'object has no attribute '__title'>>> e._test_protected()'this is a protected method'>>> e._test_private()
Traceback (most recent call last):
File "<stdin>", line 1,in<module>
AttributeError:'Employee'object has no attribute '_test_private'>>>