lists = list(range(3,31))
for vaule in lists:
if vaule % 3 != 0: #检查列表内非3倍数数值( 用 if vaule % 3 > 0: 判断语句 也是同样结果)
print(vaule,end= ' ')
lists.remove(vaule)
print()
print(lists)
以此程序运行结果为:
4 7 10 13 16 19 22 25 28
[3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30]
Python初学者,求大神详解,非常感谢