Differences between the element group and the array when python uses the in operator, and the python Operator
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.
>>> 'Jb51. net 'in ['haotu.. net ', 'jb51.. net '] True> 'jb51. net 'in ('haotu.. net ', 'jb51.. net ') True> 'jb51. net 'in ['jb51. net/codes ', 'haotu.. net '] False>' jb51. net in ('jb51. net/codes ', 'haotu.. net ') False>' jb51. net 'in ['jb51. net/codes '] False >>> 'jb51. net in ('jb51. net/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.