查看该数据类型都有哪些函数:
内置函数dir
name = "liming"
print(dir(name))
name_info = "liming"
print(name_info.count("s"))
// 结果是1
name_info = "liming"
name_info.find("查找字符",start,end)
start 默认为0 ,end默认为-1,且包含-1
find 如果找不到元素的下标值,返回 -1
name_info = "liming"
name_info.index("查找字符",start,end)
index("查找字符",start,end)
start 默认为 0 ,end默认为-1,且包含-1
index如果找不到元素的下标值,则报错
总结:find 和index函数功效一样,都是求索引。但是find找不到返回-1,而index找不到则报错。
print(" hello world ".strip()) // 结果为"hello world"
name = "liming" print(name.split("i"))
name = "liming" print(" ".join(name))
name = "liming" print(name.isdigit())