切片操作(slice)可以从一个字符串中获取子字符串(字符串的一部分)我们使用一对方括号、起始偏移量start、终止偏移量end以及可选的步长step来定义一个分片。
格式:[start:end:step]
[:]提取从开头到结尾的整个字符串
[start:]从start提取到结尾
[:end]从开头提取到end-1
[start:end]从start提取到end-1
[start:end:step]从start提取到end-1,每个step个字符提取一个
切片操作(slice)可以从一个字符串中获取子字符串(字符串的一部分)我们使用一对方括号、起始偏移量start、终止偏移量end以及可选的步长step来定义一个分片。
格式:[start:end:step]
[:]提取从开头到结尾的整个字符串
[start:]从start提取到结尾
[:end]从开头提取到end-1
[start:end]从start提取到end-1
[start:end:step]从start提取到end-1,每个step个字符提取一个