str.startswith(prefix[, start[, end]])
如果字符串以指定的 prefix 开始则返回 True,否则返回 False。 prefix 也可以为由多个供查找的前缀构成的元组。 如果有可选项 start,将从所指定位置开始检查。 如果有可选项 end,将在所指定位置停止比较。
str.endswith(suffix[, start[, end]])
如果字符串以指定的 suffix 结束返回 True,否则返回 False。 suffix 也可以为由多个供查找的后缀构成的元组。 如果有可选项 start,将从所指定位置开始检查。 如果有可选项 end,将在所指定位置停止比较。
# 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('this is a string example!!')
print('result:', result)