I want to achieve the following with str.format
:
x,y = 1234,5678
print str(x)[2:] + str(y)[:2]
The only way I was able to do it was:
print '{0}{1}'.format(str(x)[2:],str(y)[:2])
Now, this an example and what I really have is a long and messy string, and so I want to put slicing inside the {}
. I've studied the docs, but I can't figure out the correct syntax. My question is: is it possible to slice strings inside a replacement field?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…