Ryan_Li 发表于 2020-8-11 20:40:01

为什么在except下面没法给变量赋值

import pickle

def get_info():
    list=pickle.load(list, open('data.pkl', 'rb'))
    return list
try:
    list=get_info()
except :
    price=0,obj="",saved=0,a1=[],a2=[],a3=[] ,
    month1=0 , month2=0 , month3 = 1 , day1 = 0 , day2 = 0 , day3 = 0
    list=,a2,a3]
obj=input("请输入当前目标购买的物品:\n")
price=int(input("物品金额是:\n"))

except后面的price,obj,month1等变量赋值报错:can't assign to literal

zltzlt 发表于 2020-8-11 20:43:22

给多个变量赋值不是这样的,应该:

import pickle

def get_info():
    list=pickle.load(list, open('data.pkl', 'rb'))
    return list
try:
    list=get_info()
except :
    price, obj, saved, a1, a2, a3 = 0, "", 0, [], [], []
    month1, month2, month3, day1, day2, day3 = 0, 0, 1, 0, 0, 0
    list=,a2,a3]
obj=input("请输入当前目标购买的物品:\n")
price=int(input("物品金额是:\n"))

Ryan_Li 发表于 2020-8-11 20:46:35

zltzlt 发表于 2020-8-11 20:43
给多个变量赋值不是这样的,应该:

哇太谢谢啦
页: [1]
查看完整版本: 为什么在except下面没法给变量赋值