python中对于定义字符串使用双引号还是单引号没有任何区别,除非字符串中包含单引号,例下:
输出字符串内容:let's go   则需要使用双引号进行定义  a="let's go"

字符串常规操作
1.重复输入字符串
例:输出10遍hello
a="hello"
print(a*10)
2.通过索引获取字符串中的字符,进行切片操作(方法同列表切片)
例:取出变量a中的world
a="helloworld"
print(a[5:])
3.通过成员运算符判断字符串中是否存在该字符,True为存在,false为不存在
例:a="helloworld"
print('he' in a)
4.字符串拼接
众所周知,字符串是可以通过字符串a+字符串b来实现拼接的,但此方式效率极低,建议采用字符串的join方式拼接
例:a="123"
b="456"
c=''.join([a,b])
print(c)

---------以下是字符串的常用内置方法---------
st="hello world!I‘m Xin.cheng"
1.count  统计元素个数
例:st.count('H')
out:2

2.capitalize 首字母大写
例:st.capitalize()
out:Hello world!i‘m xin.cheng

※3.center   居中并自定义居中符号
例:st.center(30,'-')
out:---hello world!I‘m Xin.cheng---

4.endswith 判断字符串内容以什么字符为结尾,可以指定范围,判断方法返回布尔值
例:st.endswith('g')
out:True

※5.startswith 判断字符串内容以什么字符开头,可以指定范围,判断方法返回布尔值
例:st.startswith('hel')
out:True

※6.find 查到某字符第一个元素所处位置并返回索引值 没有查到返回-1
例:st.find('h')
out:0

※7.format  另一种格式化输出方式
例:st="hello world!I‘m {name} is {age}"
st.format(name='xin.cheng',age='18')
out:hello world!I‘m xin.cheng is 18

8.format_map 另一种格式化输出方式,以字典方式格式化输出
例:st="hello world!I‘m {name} is {age}"
st.format_map({'name':'xin.cheng','age':'18'})
out:hello world!I‘m xin.cheng is 18

9.index  另一种查找,查得到返回索引值 查不到报错
例:print(st.index('v'))
out:ValueError: substring not found

10.isalnum  判断字符串是否是字母或数字,返回结果是布尔值
11.isdecimal  判断字符串是否是十进制,返回结果是布尔值
12.isdigit/isnumeric  判断字符串是否是数字,返回结果是布尔值
13.islower  判断字符串是否全是小写,返回结果是布尔值
14.isupper  判断字符串是否全是大写,返回结果是布尔值
15.istitle  判断字符串是否是台头格式,即是否每个单词都是大写开头 返回结果是布尔值
※16.lower   字符串中所有大写变小写
※17.upper   字符串中所有小写变大写
18.swapcase  反转 字符串中所有大写变小写,小写变大写

※19.strip  去掉字符串中的空格及换行符
例:st="   hello world!I‘m Xin.chen\n"
print(st.strip())
out:hello world!I‘m Xin.cheng

※20.replace 替换字符串中的值
例:st="hello world!I‘m Xin.cheng"
print(st.replace('hello','hi'))
out:hi world!I‘m Xin.cheng
如果字符串中有多个相同值,可通过参数控制替换几个
st="hello world!I‘m Xin.cheng.cheng.cheng"
print(st.replace('cheng','hi',2))
out:hello world!I‘m Xin.hi.hi.cheng

※21.split  指定以什么为分隔符 将字符串分割 得到一个列表
例:print(st.split(' '))
out:['hello', 'world!I‘m', 'Xin.cheng.cheng.cheng']

21.title  将字符串变为台头格式 即每个单词都是大写开头