附加到列表 - 无结果 [英] Appending to list - None result

查看:27
本文介绍了附加到列表 - 无结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据:

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)

这篇关于附加到列表 - 无结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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