In [20]: 'my name is insane'.startswith('my')
out [20]: True
In [21]: 'my name is insane'.endswith('my')
out [21]: False
实战
# 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 = info.endswith('a')print('result:', result)
result = info.endswith('this is a string example!')print(result)
True
True
True
True
result: False
True
Process finished with exit code 0
目录startswith和endswith的功能startswitch和endswitch的用法startswith和endswith功能startswith 判断字符串开始位是否是某成员(元素)endswith判断字符串结尾是否是某成员(元素)startswith和endswith用法用法:string.startswith(item)string.endswith(item)item:你想查询匹配的元素,返回一个布尔值In [20]: 'my name is in