str = "hello world"
print(str[0]) # 打印第几个字符
print(str[0:5]) # 打印第一个到第几个字符
print(str[5:8]) # 左闭右开
print(str[:5])
print(str[-2]) # 打印从右边开始第几个字符
"""
\t 横向制表符 默认4个空格 linux 默认8个空格
\n 换行
\r 回车
\" 双引号 #在双引号字符串里写双引号
\' 单引号 #在单引号字符串里写单引号
\\ 失效单个字符特殊含义 #多用于路径文件操作
r 字符串不识别转义符 #多用于路径文件操作
"""
print("h\nel\tlo")
print("hel\rlo world")
print("hello w\"or\"ld") #在双引号字符串里写双引号
print('hello w\'or\'ld') #在单引号字符串里写单引号
path = "d:\\tello\image\\temp\huanzhu1.jpg"
print(path)
# 或者 r
path = r"d:\\tello\image\\temp\huanzhu1.jpg"
print(path) #多用于路径文件操作
控制台结果
h
el lo
lo world
hello w"or"ld
hello w'or'ld
d:\tello\image\temp\huanzhu1.jpg
d:\\tello\image\\temp\huanzhu1.jpg
字符串 运算
+ 字符串连接
* 重复输出字符串
[] 索引字符串 中的字符
[:] 索引字符串 中的部分字符
in 成员运算
not in 成员运算符
a = "hello"
b = "world"
print(a+b)
print(a*2)
print(a[1:5])
print(a[1])
控制台结果
helloworld
hellohello
ello
e