编写函数judgeStr(str)判断输入的字符串中是否含有Python字段,要求不区分大小写。 python
时间: 2024-01-21 12:15:57 浏览: 19
可以使用Python内置函数lower()将输入字符串转换为小写字符串,然后使用in关键字判断是否含有'python'子字符串。
代码如下:
```python
def judgeStr(str):
if 'python' in str.lower():
return True
else:
return False
```
可以进行简化,将if语句的结果直接返回即可:
```python
def judgeStr(str):
return 'python' in str.lower()
```
使用示例:
```python
str1 = "I love Python programming language."
str2 = "Java is better than python."
print(judgeStr(str1)) # True
print(judgeStr(str2)) # False
```
相关问题
请输入一个字符串,编写函数judgeStr(str)判断输入的字符串中是否含有Python字段,要求不区分大小写 Python代码
```python
def judgeStr(str):
if "python" in str.lower():
return True
else:
return False
```
使用lower()函数将字符串转换为小写,然后在小写字符串中查找是否包含"python"字符串即可。如果包含则返回True,否则返回False。
编写函数judgeStr(str)输入一个字符串,判断输入的字符串中是否含有Python字段,含有输出含有字符串,要求不区分大小写。
你可以使用Python中的字符串方法lower()将输入的字符串转换为小写,并使用关键字in来检查字符串中是否包含Python字段。下面是一个示例代码:
```python
def judgeStr(str):
if 'python' in str.lower():
print('输入的字符串中包含Python字段')
else:
print('输入的字符串中不包含Python字段')
```
注意,这个函数只是简单地判断字符串中是否包含Python,如果你需要更复杂的检查逻辑,可以根据具体需求进行修改。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)