src = 'hello, python'
# how to get 'hello'
s1 = src[:5]
# how to get 'python'
s2 = src[6:]
# how to contact 'hello' and 'python' with '!'
s3 = s1 + '!' + s2
# show the id of string above all
print(id(src))
print(id(s1))
print(id(s2))
print(id(s3))
# how to get python from the rear of src string
s4 = src[-6:]
print(s4)
Python——字符串的切片
最新推荐文章于 2024-07-04 16:04:39 发布