为什么inSetStates
,inInputAlph
和isCorrectDirection
变量False
在以下代码中被评估为:
class POC(object):
def __init__(self):
self.__set_states = (1,2,3,4,5)
self.__input_alph = ('a','b')
self.__directions = ('i','d')
def enterTransition(self):
while True:
print "enter transition tuple format:"
trans = raw_input(" Example (1,'a',2,'b','d') : ")
inSetStates = (trans[0] in self.__set_states) and (trans[2] in self.__set_states)
inInputAlph = (trans[1]in self.__input_alph) and (trans[3] in self.__input_alph)
isCorrectDirection = (trans[4].lower() in self.__directions) or (trans[4].lower() in self.__directions)
if (inSetStates and inInputAlph and isCorrectDirection):
return trans
break
else:
print "ERROR: Something is wrong"
poc = POC()
poc.enterTransition()
调试器向我展示了 tuple的three
值,并且:False
(1, 'a', 2, 'b', 'd')
inInputAlph = False
inSetStates = False
isCorrectDirection = False
self = <__main__.POC object at 0x1860690>
trans = "(1,\'a\',2,\'b\',\'i\')"
另外,我不知道这些反斜杠是什么。