2

In a string

s = 'I am a damn string'  

If I wish to remove the characters from index from 7 to 10, (i.e. to remove a slice and keep the remainder string).

I know, I can do like --

newString = s[:6] + s[11:]  

Is there any better (pythonic) way?
Thanks.

Vineet
  • 624
  • 1
  • 11
  • 26

1 Answers1

3

An alternativ could be the join method. Especially if you have more than one slice, e.g.

newString = ''.join([s[:6], s[8:12], s[16:]])
malukas
  • 106
  • 3