#切分字符串 language ="Python and Java and C++ and Golang and Scala" #split 切割字符串 生成一个列表:暂时理解为一个容器 有序序列 result =language.split("and") print(result) #2、连接序列 生成字符串 跟split 是相反的操作 lang =["Englist","Chinese","Jananese"] #通过 - 连接上面的语言 result2 = "-".join(lang) print(result2, type(result2)) #3、 删除字符串两边的空格 strip class_name =" Big Data " print(len(class_name)) #删除两边空格 class_name_new=class_name.strip() print(class_name_new,len(class_name_new)) #4、判断一个字符串是否以指定子串开始 mystr ="hello world" #mystr 以hello开始 则返回True print(mystr.startswith("hello")) #不是以world开口 则返回False print(mystr.startswith("world")) #以world结束 返回True print(mystr.endswith("world")) #判断在指定范围内是否以hello开始 print(mystr.startswith("hello", 3, 8)) print(mystr.startswith("lo", 3, 8))
字符串操作3
最新推荐文章于 2024-10-06 00:07:08 发布