第一种
已有列表 nums = [11, 22,11,33,11,44, 55,11,11],将列表中的11全部删除
nums = [11, 22, 11, 33, 11, 44, 55, 11, 11] def q(): while True: nums.remove(11) if 11 not in nums: break print(nums) q()
第二种
nums = [11, 22, 11, 33, 11, 44, 55, 11, 11] c=nums.count(11) c=0 for i in nums: if i==11: c+=1 for i in range(c): nums.remove(11) print(nums)
两种打印结果