我在python 3.5.1的环境下做了一个简单的测试,想要做到类似其他程式语言中
"private"的功能:
test.py
1 class StateMachine:
2 def __init__(self):
3 self.__state = "IDLE"
4
5 def state(self):
6 return (self.__state)
7
8 sm = StateMachine()
9 print(sm.state())
10 sm.__state = "MOV"
11 print(sm.state())
输出结果如下:
c:\python test.py
IDLE
IDLE