字符串切片
'''
字符串切片(字符串截取)
语法: [start: stop: step]
1.start => 开始索引 默认:0
2.stop => 结束索引,不包括stop 默认:到最后
3.step => 步长 默认:1
三个都有默认值,但注意不能一个都不写。
text = "hello,python"
索引:
0:h
1: e
2: l
3: l
4: o
5: ,
6: p
7: y
8: t
9: h
10: o
11: n
'''
text = "hello,python"
# 根据索引取字符串中的对应该字符
print(f'val : {text[6]}')
print(f'字符串切片1 切出python: {text[6:]}')
print(f'字符串切片1 切出python2: {text[6:12]}')
print(f'字符串切片1 切出hello: {text[0:5:1]}')
print(f'字符串切片1 切出hello2: {text[0:5:]}')
print(f'字符串切片1 切出: {text[1:10:2]}')