请输入字符串:,并用函数judgeStr(str)判断输入的字符串中是否含有Python字段,要求不区分大小写。 python代码
时间: 2024-01-21 07:16:00 浏览: 28
```python
def judgeStr(str):
if "python" in str.lower():
return True
else:
return False
input_str = input("请输入字符串:")
if judgeStr(input_str):
print("输入的字符串中包含Python字段")
else:
print("输入的字符串中不包含Python字段")
```
相关问题
请输入一个字符串:,并用函数judgeStr(str)编译Python六个字符,判断输入的字符串中是否含有Python字段,要求不区分大小写 Python代码
```python
def judgeStr(str):
if 'python' in str.lower():
return True
else:
return False
s = input("请输入一个字符串:")
if judgeStr(s):
print("输入的字符串中含有Python字段")
else:
print("输入的字符串中不含有Python字段")
```
编写函数judgeStr(str)判断输入的字符串中是否含有Python字段,要求不区分大小写。 python
可以使用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
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)