判断字符串s1中是否包含字符串s2用,
时间: 2023-10-17 20:11:04 浏览: 154
判断某字符串是否存在
可以使用Python中的in操作符来判断字符串s1是否包含字符串s2,示例如下:
```python
s1 = "hello world"
s2 = "world"
if s2 in s1:
print("s1 contains s2")
else:
print("s1 does not contain s2")
```
输出结果为:s1 contains s2
如果不想区分大小写,可以先将两个字符串都转换为小写或大写,再进行判断,示例如下:
```python
s1 = "Hello World"
s2 = "world"
if s2.lower() in s1.lower():
print("s1 contains s2")
else:
print("s1 does not contain s2")
```
输出结果为:s1 contains s2
阅读全文