Is there a way to check if an item exists in a Python tuple?

前端 未结 1 865
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 20:26

I have seen an index function but it says it errors out if it can\'t find it. Is there a simple way to just check if the item exists? I just want to get a boole

相关标签:
1条回答
  • 2021-01-17 21:13

    Use in operator:

    >>> 2 in (2, 3, 4)
    True
    

    in operator can be used to check for the membership of any element in a sequence.

    And don't name your tuple as tuple. Use a different name.

    0 讨论(0)
提交回复
热议问题