我有蟒蛇以下代码:在Python中布尔变量是否可变?
def update(request, id):
success = 0
try:
product = Mattress.objects.get(id=id)
success = 1
except Mattress.DoesNotExist:
pass
if success == 1:
return render_to_response("success.html")
else:
return render_to_response('failure.html')
这段代码检查“成功”布尔值的有效方法。如果代码通过try语句,将“成功”更改为1还是保持0?
if if == 1: – VoronoiPotato 2012-08-10 20:29:45
你的代码中没有布尔值,你也不会改变任何东西。 – BrenBarn 2012-08-10 20:30:47
这段代码有很多问题。 – Wug 2012-08-10 20:31:03