s ="itsastring"
#if you add any variable in left side then python will start slicing from there
#and slice to one less than last index assigned on right side
newS = s[:]
s = [11,22,33,44,55,66,77]
s[3:3] = [1,2,3] # insertion at position 3
print( s )
s = [11,22,33,44,55,66,77]
s[3:4] = [1,2,3] # deletion of element at position 3, and then insertion
print( s )
s = [11,22,33,44,55,66,77]
s[3:6] = [1,2,3] # deletion of elements from position 3 to 5, and then insertion
print( s )
s = [11,22,33,44,55,66,77]
s[:] = [1,2,3] # deletion of all elements, and then insertion : whole replacement
print( s )
希望有帮助:
因此
[:0]
意味着将字符串从beggining分割到0
字符串中的s
元素(或者再次是第一个),结果是什么都没有。默认情况下,从第一个元素到最后一个元素进行切片,或者print(s[0:])
与print(s)
相同我建议您尝试在整个字符串中循环如下:
如果S和T是序列,}与{}是一样的:所以它是在前面的一个简单插入
S[a:b] = T
将用T的元素替换S的索引a到b-1的子序列如果
a == b
,它将充当一个简单的插入。而且{
输出:
相关问题 更多 >
编程相关推荐