16

When I am trying to print a string like the one below which uses an apostrophe in the sentence,

print(''I am jack's raging bile duct'')

I get a syntax error. How to fix this?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
user1940012
  • 181
  • 1
  • 1
  • 4
  • 1
    You can also use `'''` or `"""` if you absolutely hate backslashes (as you should :). ie. `'''"Isn't this cool?"'''` – Derek Litz Dec 31 '12 at 18:55

6 Answers6

33

You can use both " and ' to write a string in Python, a double ' ('') will be invalid.

If you use ", the syntax for your case would be

print("I am jack's raging bile duct")

But if you use ', you may need to escape the apostrophe as follows:

print('I am jack\'s raging bile duct')

In general, if you use ", and your string has also ", you will need to escape every " in your string, except the one that closes, same happens with '.

wovano
  • 4,543
  • 5
  • 22
  • 49
iferminm
  • 2,019
  • 19
  • 34
8

There are 2 ways:

print('I am jack\'s raging bile duct')

or:

print("I am jack's raging bile duct")
5

Don't use double ', use ".

print("'I am jack's raging bile duct'")
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
gefei
  • 18,922
  • 9
  • 50
  • 67
1

Use of double quotes will do the trick. print("I am jack's raging bile duct") I tried it and works good. Happy coding!

apurba
  • 19
  • 1
0

'' is not a double quote.
You want ".

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
-3

you have 3 way:

  • """ it's python """
  • " it's python "
  • ' it\'s python '

in general you just can use different of mark it maean use " in ' OR use ' in ".

Mahdi Ebi
  • 15
  • 2