-1

thanks to answers on this site I now know that you can remove the last characters of a string by string[:-1] which was really helpfull, however I need to be able to remove the first aswell and as far as I understand this technique it is not possible. so are there other ways to remove parts of strings without replacing spesific letters?

thegunmaster
  • 265
  • 4
  • 14

2 Answers2

6

What do you mean "it is not possible"? :)

It is perfectly possible with Explain Python's slice notation:

>>> mystr = 'abcde'
>>> mystr[1:] # Remove the first
'bcde'
>>> mystr[1:-1] # Remove the first and the last
'bcd'
>>> mystr[2:-2] # Remove the first two and the last two
'c'
>>>
Community
  • 1
  • 1
1

string[1:]

You may need to read some documentation. :)

pvgoran
  • 442
  • 3
  • 14