pop的运用

pop():弹出列表最后一个元素

练习题:

num_list =  [12, 45, 34,13, 100, 24, 56, 74, 109]
one_list = []
two_list = []
three_list = []
while len(num_list) > 0:
    num_pop = num_list.pop()
    if num_pop % 3 == 0:
        one_list.append(num_pop)
    elif num_pop % 3 == 1:
        two_list.append(num_pop)
    else:
        three_list.append(num_pop)
print("被3整除的有:",one_list)
print("取余为1的有:",two_list)
print("取余为2的有:",three_list)

运行结果:

被3整除的有: [24, 45, 12]
取余为1的有: [109, 100, 13, 34]
取余为2的有: [74, 56]
原文地址:https://www.cnblogs.com/zyqomj/p/10999444.html