【发布时间】:2018-05-05 13:56:02
【问题描述】:
v = ('* '*5).split()
print v, len(v), type(v)
print v.append(5)
输出:
['*', '*', '*', '*', '*'] 5 <type 'list'>
None
为什么尝试附加 v 会导致输出为 None?如图所示,v 是长度为 5 的列表类型,但 append 似乎仍然不起作用。
我可以做些什么来追加到 v?
我的具体情况
我有一个列表列表:
m = [[1, 2, 3, 4],[5, 6, 7, 8],[1, 2, 3, 4]]
m.append(('* '*5).split().append(" "))
这不起作用,因为我正在尝试将 None 附加到 m。
我怎样才能返回这个附加列表而不是打印它,以便我返回列表而不是 None?
【问题讨论】:
-
您使用哪种语言进行编程?为什么不将其添加为标签?您已经阅读过the help pages,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。也请take the tour 和read about how to ask good questions。最后请学习如何创建Minimal, Complete, and Verifiable Example。
-
@Someprogrammerdude 糟糕,忘记添加语言了。这怎么不是一个完整的例子?而且我看不出这如何适合不应该问的问题。
-
您想要的是
list对象支持流畅的界面。他们没有。