用python查找字符串pdfName中,是否存在下划线,是返回true,否返回false
时间: 2023-05-29 10:04:15 浏览: 46
下面是一个Python函数,用于检查给定字符串中是否存在下划线。如果存在,则返回True;否则返回False。
```python
def check_underscore(pdfName):
if "_" in pdfName:
return True
else:
return False
```
你可以调用这个函数,并传递一个字符串参数来检查该字符串中是否包含下划线。例如:
```python
pdfName = "example_file.pdf"
if check_underscore(pdfName):
print("The filename contains an underscore.")
else:
print("The filename does not contain an underscore.")
```
运行上面的代码,将打印出字符串“ The filename contains an underscore.”,因为字符串“ example_file.pdf”中包含一个下划线。