说明
检测字符串以指定的值开头,则 startswith() 方法返回 True,否则返回 False。
语法
string.startswith(value, start, end)
value --- 要搜索的值
start --- 开始索引位置
end--- 结束索引位置(搜索的时候包括start,不包括end)
示例
# python 字符串方法startswith(value,start,end) 左闭右开
txt = "Hello, welcome to my world."
x = txt.startswith("wel", 7, 10)
print(x)
**注意它是字符串方法,所以在Numpy, pandas中使用时,要先转换为字符串,eg:
import numpy as np
import pandas
from pandas import Series,DataFrame
df=DataFrame(np.random.rand(6,4)*2-1)
df
df.columns=['A','B','C','D']
df.index=['a','b','c','d','e','f']
df['E']=['one','two','three','one','two','three']
df