0

What is the equivalent of string c# = @"\hello" in python? python = '\hello'
In other words, how would I bypass the '\'' breakpoint in python?

dreftymac
  • 29,742
  • 25
  • 114
  • 177
Symbios
  • 17
  • 1
  • 6
  • What do you mean by `bypass` ? if it means just getting the `hello` string then you can try `'\hello'.split('\\')[1]` – python Jun 26 '16 at 18:59

3 Answers3

3

Assuming you mean that you want \ to not act like an escape character, then you simply escape \ with another \:

myString = "\\hello"
print myString

This prints:

\hello

You also can use a "raw" string:

myString = r"\hello"
IanPudney
  • 5,747
  • 1
  • 21
  • 37
2

"I am 6'2\" tall." # escape double-quote inside string

'I am 6\'2" tall.' # escape single-quote inside string

enter image description here

ΦXocę 웃 Пepeúpa ツ
  • 45,713
  • 17
  • 64
  • 91
0

A general rule of thumb in any programming language to print the escape character or use it as a part of string is to escape the escape character. So

>>print "\\hello"
\hello

Also as pointed by @IanPudney , python provides a special mechanism to print the raw string. Just use print r"\hello"

I hope this helps

Prakhar Agrawal
  • 964
  • 11
  • 21