Sometimes, to determine whether a number is in a sequence, the in operator is used to determine the membership. if the condition is true, true is returned. if the condition is false, returns a flase. Such an operator is called a Boolean operator, and its true value is called a Boolean value. In python, you can use the in symbol to determine whether the specified element exists in the list. However, I found that there are differences between tuples and arrays. The following is the detailed experiment result.
>>> 'Bitscn. com 'in ['haotu. net', 'bitscn. com '] True> 'bitscn. com 'in ('haotu. net', 'bitscn. com ') True> 'bitscn. com 'In ['bitscn. com/codes ', 'haotu.. net '] False >>> 'bitscn. com 'in ('bitscn. com/codes ', 'haotu.. net ') False >>> 'bitscn. com 'In ['bitscn. com/codes '] False >>> 'bitscn. com 'in ('bitscn. com/codes ') True
The first five Tests all conform to our expectation. there is only the last one. after the array is replaced with a tuples, python treats the tuples as strings when there is only one element in the tuples, I don't know why there is such a processing method, but I should pay attention to it during development. when I only use the in statement to determine whether there are elements in the array, it is best to use the [] array instead of the tuples.
The above is all the content of this article. I hope you will like it.