1.字符串的定义:字符串是一个有序的字符的集合
2.字符串的切片操作
#切片操作 字符串的底部其实是list, 因此可以进行切片操作 是左闭右开的
a = "hello, world"
print(a[0:3]) #结果为hel 即下标从0开始到下标为3-1的元素输出
3.字符串的常用函数
#1.center 将字符串包围起来,参数为字符个数以及左右两边的参数
a="hello, world"
print(a.center(50,"-")) #-------------------hello, world-------------------
#2.count 将字符串含有多少个"l"计数
print(a.count("l")) #3
#3.endswith & startswith 判断字符串的开头或结尾是否为这些元素
print(a.endswith("ld")) #True
print(a.startswith("he"))#True
#4.find 判断字符串中是否含有这个元素,如果有返回序列号,如果没有则返回-1
print(a.find("or")) #8
#5.isdigit 判断字符串中的元素是由由数字组成
print(a.isdigit()) #False
b = "12345"
print(b.isdigit()) #True
#6."".join 用所给元素将列表中各值拼接起来形成字符串
l = ["hello","world"]
print("-".join(l)) #hello-world
#7.replace 将字符串的某个元素替换成另一个
print(a.replace("w","W")) #hello, World
#8.strip 去掉字符串前后的回车以及空格
c = "\n hello, world \n"
print(c.strip()) #hello, world
#9.split 使用特定的元素将字符串分割成不同部分组成列表 默认使用空格进行分割
print(a.split("l")) #['he', '', 'o, wor', 'd']