tp 查询逗号分割的字符串 FIND_IN_SET
时间: 2023-10-12 07:04:47 浏览: 189
如果您想在逗号分割的字符串中使用类似于MySQL中的FIND_IN_SET函数进行查询,可以使用以下方法:
```python
def find_in_set(item, string):
items = string.split(",")
if item in items:
return True
return False
string = "apple,banana,orange"
item = "banana"
result = find_in_set(item, string)
print(result)
```
输出:
```
True
```
在这个例子中,`find_in_set`函数接受一个要查找的元素和一个逗号分割的字符串作为参数。它将字符串拆分成一个列表,并检查要查找的元素是否在列表中。如果找到了,则返回`True`,否则返回`False`。
您可以根据需要调用`find_in_set`函数,并传入相应的要查找的元素和逗号分割的字符串。
希望这可以帮助到您!如果您还有其他问题,请随时提问。
阅读全文
相关推荐










