Question: I want to get rid of characters in a string that comes after \ in python

```
df5['Abbreviation'] = df5['Abbreviation'].str.strip('\')
df5['Data Type'] = df5['Data Type'].str.strip('\')

```

error message:

```
File "<ipython-input-150-c7763a76caaf>", line 1

    df5['Abbreviation'] = df5['Abbreviation'].str.strip('\')
                                                            ^
SyntaxError: EOL while scanning string literal

```

Answer: 
As mentioned with MrGeek's answer, you must escape the backslash. 

If you want to remove anything after the backslash, simply do the following:

```
test_str = test_str.str.split('\\')[0] 

```

The .split returns an array, and since we only want the contents leading to the first backslash, we can just get the first index using [0].

This will get everything up until the first backslash. If you want to include the backslash, then just append it at the end:

```
test_str = test_str.str.split('\\')[0] + "\\"

```
As mentioned in MrGeek's answer, you need to add two slashes to fix the initial syntax error. To remove everything after a backslash or special character such as a newline is found, no matter what it is, I found the simplest solution is this:

```
string = "Hello Stack \n\r\rOverflow!"
output = ""
print("In:", string)

for char in string:
    if char == "\\" or char == "\n" or char == "\r":
        break
    else:
        output += char

string = output
print("Out:", string)

```

Which Outputs:

```
In: Hello Stack 
Overflow!
Out: Hello Stack 
>>> 

```

This doesn't seem to be the *most* efficient way of doing it, but for small strings like your use case appears to be, the impact is unnoticable and does what is intended.