Greeny_su
Greeny_su
2020-06-15 01:05
采纳率: 0%
浏览 213

python中,已经定义的列表运行后报错name 'income_list' is not defined 未定义??

代码如下

list1 = [['a1', '2020-01-01', '2000', 'x1'], ['a2', '2020-02-02', '200', 'x2'], ['a3', '2020-01-03', '2000', 'x3'], ['b1', '2020-04-04', '300', 'x4'], ['b2', '2020-05-10', '350', 'x5'], ['b3', '2020-06-07', '600', 'x6'], ['b4', '2020-01-08', '100', 'x7']]

def iemax():

    income_list = []
    expend_list = []   
    dictin = {}   
    dictex = {}
    jine = 0
    for i in range(0,len(list1)):
        name = list1[i][0][0]
        if name == 'a':
            jine = list1[i][2]
            income_list.append(jine)
            dictin.setdefault(list1[i][0],list1[i][2])
        elif name == 'b':
            jine = list1[i][2]
            expend_list.append(jine)
            dictex.setdefault(list1[i][0],list1[i][2])
iemax()

运行后不报错。但输入income_list, expend_list, dictin, dictex试图查看内容

均报错
name 'income_list' is not defined ,

请问有人知道是为什么吗?我在函数中不是已经定义过了吗

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • qq_45569373
    二十不忘 2020-06-15 08:52

    图片说明

    点赞 评论

相关推荐