字符串中添加引号
str = '"你好"'
print(str)
str1 = "'大家好'"
print(str1)
str2 = '你好\'啊'
print(str2)
运行结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/80bf7fe29aeba0c7263b43e4438e26d6.png)
字符串截取
格式:str1 = str[开始索引:结束索引]
不包括结束索引
str = "hellopython"
str1 = str[0:5]
print(str1)
运行结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/05499e3b79683d05924bc67e23b7fba4.png)
格式:str1 = str[开始索引:结束索引:步长]
不包括索引
str = "hellopython"
str1 = str[0:5:2]
print(str1)
运行结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a0626de00845aff042dec18b05e5c8c0.png)