class ModeBool():
def __init__(self, mode):
self.mode = mode
class IndexOfBool():
def __init__(self, lst):
'''
Creates a list of True's as it's elements based on the given number.
>>> i1 = IndexOfBool(5)
Should create -> [True, True, True, True, True]
'''
self.lst = [ModeBool(True) for i in range(lst)]
def bool_true(self):
new_lst = []
for index, element in enumerate(self.lst):
if element is True:
new_lst.append(index)
return new_lst
然而,當我打電話bool_true
它不返回正確的結果:返回元素的索引列表中的
i1 = IndexOfBool(10)
i1.bool_true()
[]
它應該已經返回:
i1 = IndexOfBool(10)
i1.bool_true()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
不是太確定爲什麼它不會返回所期望的。另外,如果我要用ModeBool(False)
替換ModeBool(True)
,則應該創建一個False
s的列表。如果我在False
的列表上撥打bool_true
,那麼它應該是return []
。
什麼'ModeBool'點? –
哦,我要添加更多的東西。 – Sc4r
您可以使用'print'語句來定期調試腳本,以查看變量實際指向的內容。如果你在'IndexOfBool'類的'__init__'方法的末尾放置'print self.lst',你會立即發現問題。 –