Python not finding item in list

后端 未结 2 1303
旧时难觅i
旧时难觅i 2021-01-27 08:34

I am just trying out some basic functionality in Python, and this is the entire script that I wrote:

a = [5, 3, 6, 9, 7, 8]
x = input()
print(x in a)
         


        
2条回答
  •  逝去的感伤
    2021-01-27 09:06

    In Python 3.x, the function input() returns a string. Since the list a contains integers, you have to convert the input to int:

    x = int(input())
    

提交回复
热议问题