s = 'hello'
s1 = slice(3, 5)
s2 = slice(1, 4, 2)
print(s[s1])
# lo
print(s[s2])
# el
print(s2.start) # 1
print(s2.stop) # 4
print(s2.step) # 2
slice切片
最新推荐文章于 2024-04-24 21:14:07 发布
s = 'hello'
s1 = slice(3, 5)
s2 = slice(1, 4, 2)
print(s[s1])
# lo
print(s[s2])
# el
print(s2.start) # 1
print(s2.stop) # 4
print(s2.step) # 2