Python not finding item in list

后端 未结 2 1304
旧时难觅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())
    
    0 讨论(0)
  • 2021-01-27 09:22

    Cast the input to int. input() always returns a string

    x = int(input())
    
    0 讨论(0)
提交回复
热议问题