单选题
适中
#15933
关于下列代码运行结果的说法,错误的是? ( ) scores = [58, 72, 85, 64, 43, 90, 56] HeGe = (score for…
关于下列代码运行结果的说法,错误的是? ( )
scores = [58, 72, 85, 64, 43, 90, 56] HeGe = (score for score in scores if score >= 60) #筛选合格的同学 ZongFen = sum(HeGe) #计算合格同学们的总分 RenShu=len(HeGe) #统计合格同学的人数 print(RenShu)
答案与解析
正确答案:C
解析
生成器推导式(score for score in scores if score >= 60)会生成一个生成器对象。调用sum(HeGe)会消耗生成器中的所有值,因此后续调用len(HeGe)时,生成器已经为空,生成器对象没有元素。