# 1.切分字符串
language = "Python and Java and C++ and Golang and Scala"
# split 切割字符串生成一个列表:暂时理解为一个容器 有序序列
rst1 = language.split("and")
print(rst1)
# 2.链接序列 生成字串符 跟split 是相反操作
lang = ["English", "Chinese", "Japaneses"]
# 通过 - 连接上面的语言
rst2 = "-".join(lang)
print(rst2, type(rst2))
# 3.删除字符串两边的空格 strip
class_name = " Big Data "
print(class_name, len(class_name))
# 删除两边空格
rst3 = class_name.strip()
print(rst3, len(rst3))
# 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("l
Python基础 字串符操作与列表操作
最新推荐文章于 2024-07-24 23:49:50 发布