-6

Python how to remove = in strings?

a = 'bbb=ccc'

a.rstrip('=')
# returns 'bbb=ccc'

a.rstrip('\=')
# alse returns 'bbb=ccc'

how to match = ?

rootpetit
  • 381
  • 1
  • 7
  • 21
  • 2
    You should probably take some time to [read the `rstrip` documentation](https://docs.python.org/3/library/stdtypes.html#str.rstrip), and learn what it actually do. – Some programmer dude Mar 08 '18 at 08:08
  • I misunderstood. thanks – rootpetit Mar 08 '18 at 08:10
  • Possible duplicate of [Remove specific characters from a string in Python](https://stackoverflow.com/questions/3939361/remove-specific-characters-from-a-string-in-python) – moooeeeep Mar 08 '18 at 09:11

3 Answers3

3

You can replace it with an empty string:

a.replace("=", "")

For reference:

moooeeeep
  • 30,004
  • 18
  • 92
  • 173
0

You can use the replace method (easiest):

a = 'bbb=ccc'
a.replace('=', '')

or the translate method (probably faster on large amounts of data):

a = 'bbb=ccc'
a.translate(None, '=')

or the re.sub method (most powerful, i.e. can do much more):

import re
re.sub('=', '', 'aaa=bbb')
thebjorn
  • 24,226
  • 9
  • 82
  • 127
0

strip removes characters from the beginning and from the end of the string! From the documentation:

 str.strip([chars]) 

Return a copy of the string with leading and trailing characters removed. 

Since you "=" is neither at the beggining nor at the end of your string, you can't use strip for your purpose. You need to use replace.

a.replace("=", "")
Psytho
  • 3,025
  • 1
  • 17
  • 25