remove unwanted characters from string python code example
Example 1: python remove last characters from string
st = "abcdefghij"
st = st[:-1] # Returns string with last character removed
Example 2: remove special characters from string python
>>> string = "Special $#! characters spaces 888323"
>>> ''.join(e for e in string if e.isalnum())
'Specialcharactersspaces888323'
Example 3: drop all characters after a character in python
sep = '...'
stripped = text.split(sep, 1)[0]