del code;将原列表里面的内容清空以后出现这样的错误正常吗?
来源:3-3 编程练习
每天两杯冰美式
2023-01-02 02:19:39
以下为运行结果:
******下面这两行是错误提示****** print("清空原列表编码", code) NameError: name 'code' is not defined ***************************** 字符串添加完成 ['e_ying', 'd_shi', 'a_wo', 'f_xiong', 'b_men', 'c_dou'] 数字添加完成 [6, 1, 2, 3, 4, 5] 新字符串列表排序 ['a_wo', 'b_men', 'c_dou', 'd_shi', 'e_ying', 'f_xiong'] 新数字列表排序 [1, 2, 3, 4, 5, 6] 反转后的新字符串列表crack_list ['f_xiong', 'e_ying', 'd_shi', 'c_dou', 'b_men', 'a_wo'] 反转后的新数字列表number_list [6, 5, 4, 3, 2, 1] 复制原编码 ['e_ying', 'd_shi', 6, 'a_wo', 1, 2, 3, 'f_xiong', 'b_men', 4, 5, 'c_dou'] 进程已结束,退出代码1
1回答
同学,你好!del code会删除整个列表,并不是清空。因此会报错。应使用code.clear()清空列表
祝学习愉快!
相似问题