打印LIST列表作为输出 [英] print the lists of LIST as output

查看:592
本文介绍了打印LIST列表作为输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,它为for循环中的n的不同值提供输出作为不同的列表.我必须将这些列表一起显示为程序的最终输出.
假设:
#####
对于范围(0,2)中的n:
当n = 0的结果是LIST1
当n = 1结果是LIST2
当n = 2的结果是LIST3

至于程序的最终输出,我需要显示:

LIST1
LIST2
LIST3
#####

这个怎么做?我想我必须创建一个新列表来存储n的不同值,但是我该怎么做呢?

I''ve a program which gives output as different lists for different values of n in for loop. I''ve to display these lists all together as final output of the program.
Suppose:
#####
for n in range(0,2):
when n=0 result is LIST1
when n=1 result is LIST2
when n=2 result is LIST3

as for the final output of the program I need to display:

LIST1
LIST2
LIST3
#####

How to do this? I think I''ve to create new list to store the different values of n, but how can I do it?

推荐答案

这甚至无法编译,但是也许您只需要设置问题文本的格式即可.请使用改善问题"和<pre>标签作为源代码.

当原始想法错误时,为什么还要提供代码帮助?所有那些重复的条件语句都是邪恶的. (您可能说的是"if",而不是when.)那些LIST1LIST2 ..是从哪里得到的?您根本不应该拥有这些变量,它们应该是list[0] ...首先,您认为数组的用途是什么.在这种情况下,如果不是,就只是一个循环.

在阅读文档 http://www.python.org/doc/之前,询问非常基本的语法没有任何意义. [^ ].

—SA
This won''t even compile, but maybe you just need to format the text of your question. Please use "Improve question" and <pre> tags for source code.

Why helping with the code when the original idea is wrong? All those repeated conditional statements are evil. (You probably meant "if", not when".) Where did you get those LIST1, LIST2..? You should not have these variables at all. They should be list[0], list[1]… in first place. What do you think arrays are for. In this case, no ifs no buts, just one loop.

It makes no sense to ask about very basic syntax before you read the documentation http://www.python.org/doc/[^].

—SA


这篇关于打印LIST列表作为输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆