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
  • 31,404
  • 26
  • 119
  • 182
Symbios
  • 17
  • 2
  • 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,941
  • 1
  • 24
  • 39
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 ツ
  • 47,427
  • 17
  • 69
  • 97
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
  • 1,002
  • 12
  • 21