我如何打印最终列表结果而不是以前的列表呢?

时间:2018-05-12 04:53:28

标签: python list printing

如标题所示,

<form id="newsletterForm">
    <div>
         <input type="email" id="newsletterInput" name="email" placeholder="Email Address *"><input type="submit" id="newsletterSubmit">
    </div>
    <!--// inside of the form //-->
    <div id="newsletterValidate"></div>
</form>

multiples_of_3(3,9)

2 个答案:

答案 0 :(得分:1)

print(storage_list)移出forloop

In [3]: def multiples_of_3(x, y):
   ...:     y = y + 1
   ...:     storage_list = []
   ...:     for i in range(x, y):
   ...:         if i % 3 == 0:
   ...:             storage_list.append(i)
   ...:     print(storage_list)
   ...:
   ...:

In [4]: multiples_of_3(3, 9)
[3, 6, 9]

In [5]:

答案 1 :(得分:0)

我以下是你想要的:

def multiples_of_3(x, y):
    y = y + 1
    storage_list = []
    for i in range(x, y):
        if i % 3 == 0:
            storage_list.append(i)
    print(storage_list)

multiples_of_3(3, 9)

你只需要将print语句带到if和for循环之外,这样只有当这两个语句都执行完毕时才打印。