What Is the Fastest Way to Check if a Value Exists in a Python List?


The fastest way to check if a value exists in a Python list is by using the "in" keyword.


my_list = [1, 2, 3, 4, 5]

if 3 in my_list:
    print("Value exists")
    print("Value does not exist")


Value exists

Latest Questions

python How to Fix ""zsh: command not found: python" Error on MacOS X? python How to Fix "xlrd.biffh.XLRDError: Excel xlsx file; not supported" Error in Pandas? python How to Remove All Whitespace From a Python String?