# Python 字符串的startswith和endswith函数


### 字符串的startswith和endswith函数

#### 功能

- `startswith`判断字符串**开始位**是否是某成员(元素)
- `endswith`判断字符串**结尾**是否是某成员(元素)

#### 用法

- `string.startswith(item)` -> `item` : 你想查询匹配的元素,返回一个**布尔值**
- `string.endswith(item) ` -> `item`: 你想查询匹配的元素,返回一个**布尔值**

#### 小发现

当`item`赋值为`''`时,始终返回为`True`

#### 代码

```python
# coding:utf-8

info = 'this is a string example!!'

result = info.startswith('this')
print(result)

result = info.startswith('this is a string example!!')
print(result)

print(bool(info == 'this is a string example!!'))

result = info.endswith('!')
print('result:', result)

result = info.endswith('this is a string example!!')
print('full?:', result)

```


