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