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 に答える