strip()去除字符串两边的指定字符(默认去除的是空格)
案例学习:
str1="today is a nice day"
str2="***today is a nice day***"
# print(str1)
print(str1.strip())
# print(str2)
# print(str2.strip("*"))
# lstrip() 只去除字符串左边的指定字符
# print(str2.lstrip("*"))
# rstrip() 只去除字符串右边的指定中字符
# print(str2.rstrip("*"))
# 字符串的分割和合并
# split() 以指定字符对字符串进行分割(默认是空格)
str3="this is a string example...."
print(str3.split()) ['this','is','a','string','example....']
# print(str3.split("i"))
#['th','s a str','ng example....']
# join() 合并字符串
str4 = "-"
tup = ("hello","every","body")
print(tup)
print(str4.join(tup))
输出结果如下:
today is a nice day
today is a nice day***
today is a nice day***
today is a nice day******
today is a nice day['this','is','a','string','example....']
['th','s','s a str','ng example....']
('hello','every','body')
#python入门#Python编程技巧#Python组合数据类型#数据处理实战#字符串提取与分割#Python学习笔记