2015-09-26 61 views
-1
test = "123213 32543543 52354 234 34" 
a = test.split().append("sd") 
print (a) 

将上面的代码给我输出无后追加,而下面的代码将输出一个列表:为什么我不能直接在Python分裂

test = "123213 32543543 52354 234 34" 
a = test.split() 
a.append("sd") 
print (a) 

任何人都可以解释一下吗?谢谢。

回答

2

这是因为.append()列表操作返回None

In [1]: list1 = [1,2,3,4] # some list 

In [2]: a = list1.append(5) # append '5' to the list and assign return value to 'a' 

In [3]: print a 
None # means '.append()' operation returned None 

In [4]: list1 
Out[4]: [1, 2, 3, 4, 5] 

In [5]: list1.append(6) 

In [6]: list1 
Out[6]: [1, 2, 3, 4, 5, 6] 
1

some_list.append()不返回列表some_list,它返回None,这就是为什么

相关问题