#-*-coding:utf-8-*-'''字符串索引与切片'''# 索引s = 'bowen's1 =s[0] # bprint(s1)# 切片,包头不包尾s2 = s[:3]print(s2) # bows3 = s[-1]print(s3) # ns4 = s[-2]print(s4) # es5 =s[:]print(s5) # 复制s6 = s[0:0]print(s6)
二、隔空取
#-*-coding:utf-8-*-'''字符串索引与切片'''# 索引s = 'bowen'# 隔空取,首尾,步长s7 = s[0:5:2]print(s7)
三、倒着取
#-*-coding:utf-8-*-'''字符串索引与切片'''# 索引s = 'bowen'# 倒取,首尾,步长s7 = s[-1::-1]print(s7)
#-*-coding:utf-8-*-'''字符串索引与切片'''# 索引s = 'bowen'# 倒取,首尾,步长s7 = s[::-1]print(s7)