'Can't remove backslash from string in Python

I want to remove backslash from a string,

I tried result.replace('\\','') but nothing changed.

Anyone has an idea how I can remove it?

result = '[(\'company_ids\', \'in\', company_id), (\'warehouse_ids\', \'in\', warehouse_id)]'



Solution 1:[1]

The backslashes are not part of your string. They are there because you used simple quote inside a quote defined using simple quotes, but internally they are not existing. You can see it if you replace by double quotes.

>>> result = '[(\'company_ids\', \'in\', company_id), (\'warehouse_ids\', \'in\', warehouse_id)]'
>>> print(result)
[('company_ids', 'in', company_id), ('warehouse_ids', 'in', warehouse_id)]

Solution 2:[2]

it's no a part of the string but you can use result.replace("\","") to remove it

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Floh
Solution 2 Shilal