I am trying to assign
user = 'corp\adam'
Using python I am unable to create a user variable as desire. Desired Output:
user
'corp\adam'
I don't want to print the variable. I need to store it.
I am trying to assign
user = 'corp\adam'
Using python I am unable to create a user variable as desire. Desired Output:
user
'corp\adam'
I don't want to print the variable. I need to store it.
In Python (and commonly in other programming languages too) the backslash character is used to denote special characters that could not be typed directly into a string. This is known as an escape sequence. To specify a literal backslash, use it twice:
user = 'corp\\adam'
Try a double backslash, i.e. corp\\adam. The first backslash denotes that the second one has to be evaluated like a normal character, not as another escape character.
You can use r'corp\adam'
that way you tell Python it's a "raw" string and the backslash will not be used to escape other characters.
From the docs:
Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters.
The backslash character acts as an escape when the next character is an ASCII or Python special escape character. Either escape the backslash with another backslash:
'corp\\adam'
or use a raw string (where backslash only escapes the quote character it doesn't even escape itself):
r'corp\adam'