0

嗨,谁能告诉我如何检查变量值是否在数组中,或者不像我有

variable = 17.40
array = [14.40,14.12,45.50.....]

需要检查变量值是否存在

编辑我尝试了以下但它不起作用

scoremx = [19,18,17]
style_score=score.objects.get(user_id=request.user.id)
if style_score.style_quiz_score in scoremx: 

it goes in else cxondition but it has the 19 value in database
4

2 回答 2

3

尝试这个:

if int(style_score.style_quiz_score) in scoremx:
    pass 

您无法比较 int 和 float。你应该这样做:

if 17 <= style_score.style_quiz_score < 20:
   pass
于 2013-02-21T11:21:58.350 回答
1
if variable in array:
    #do something
于 2013-02-21T11:06:41.380 回答