本文介绍了追加到列表-无结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据:
lis_t = [['q', 'w', 'e'],['r', 't', 'y']]
预期结果:
lis_t = [['q', 'w', 'e', 'u'],['r', 't', 'y']]
问题描述:我试图添加到上面的列表中,但是无法添加相同的内容,因为它以某种方式导致没有结果.请帮助我了解我在做什么错.
problem description: I am trying to append to the list above however not able to append the same as it somehow results in none. Please help me understand what am I doing wrong.
编写代码:
lis_t = [['q', 'w', 'e'],['r', 't', 'y']]
lis_t[0] = lis_t[0].append('u')
print(lis_t[0])
print(lis_t)
输出:
None
[None, ['r', 't', 'y']]
推荐答案
lis_t [0] .append('u')
会返回 None
值,然后您分配这是 lis_t [0]
的原因,这就是为什么您获得 None
值
lis_t[0].append('u')
this returns None
value and then you assigning this to lis_t[0]
that's why you are getting None
value
lis_t = [['q', 'w', 'e'],['r', 't', 'y']]
lis_t[0].append('u')
print(lis_t)
这篇关于追加到列表-无结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!