我创建了一个课程:
class aTest:
name = ""
twoGroups = -1
continuous = -1
parametric = -1
covariates = -1
paired = -1
def __init__(self, name, twoGroups, continuous, parametric, covariates, paired):
self.name = name
self.twoGroups = twoGroups
self.continuous = continuous
self.parametric = parametric
self.covariates = covariates
self.paired = paired
然后创建一个类实例列表:
testList = []
testList.append(aTest("independent samples t-test", 1, 1, 1, 0, 0))
testList.append(aTest("dependent samples t-test", 1, 1, 1, 0, 1))
testList.append(aTest("Mann-Whitney U-test", 1, 1, 0, 0, 0))
testList.append(aTest("Wilcoxson matched pairs test", 1, 1, 0, 0, 1))
testList.append(aTest("one-way independent ANOVA", 0, 1, 1, 0, 0))
testList.append(aTest("Kruskall-Wallis test", 0, 1, 0, 0, 0))
testList.append(aTest("one-way repeated measures ANOVA", 0, 1, 1, 0, 1))
testList.append(aTest("Friedman's ANOVA", 0, 1, 0, 0, 1))
testList.append(aTest("ANCOVA", 0, 1, 1, 1, 0))
然后,最后,我尝试删除列表中属性parametric
等于0的所有项目:
print("Now, remove the nonparametric tests...")
for test in testList:
if test.parametric == 0:
testList.remove(test)
print("...and print what's left, with confirmation the attribute was 0")
for test in testList:
print(test.name+", "+str(test.parametric))
我在控制台中得到以下结果:
> Now, remove the nonparametric tests...
> ...and print what's left, with confirmation the attribute was 0
> independent samples t-test, 1
> dependent samples t-test, 1
> Wilcoxson matched pairs test, 0
> one-way independent ANOVA, 1
> one-way repeated measures ANOVA, 1
> ANCOVA, 1
Wilcoxson matched pairs test
命名对象发生了什么事?