qq_26174289
奈陌real
2021-01-21 22:45

python append()方法混乱

  • python
  • list
json = {
    "test": [
        {
            "num": "0",
            "char": "a"
        },
        {
            "num": "1",
            "char": "b"
        },
        {
            "num": "3",
            "char": "c"
        }
    ]
}
num_list = char_list = []
for i in json['test']:
    num_list.append(i['num'])
    char_list.append(i['char'])
print(num_list)
print(char_list)

按照我的思路,应该是num_list中只有num元素,char_list中只有char元素

但实际上,两个列表输出是一样的

['0', 'a', '1', 'b', '3', 'c']
['0', 'a', '1', 'b', '3', 'c']

请问为什么?

  • 点赞
  • 收藏
  • 复制链接分享

2条回答