15

Eg.

when iam trying to write something like below which uses an apostrophe in the sentence,

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

I get invalid syntax error. How to fix this?

SLaks
  • 800,742
  • 167
  • 1,811
  • 1,896
user1940012
  • 163
  • 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

5 Answers5

26

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 '.

iferminm
  • 1,841
  • 17
  • 32
7

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'") should work

gefei
  • 16,986
  • 6
  • 47
  • 64
2

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
  • 21
  • 1
0

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

SLaks
  • 800,742
  • 167
  • 1,811
  • 1,896
  • Man, I thought double clicking the (') key produces (") Turns out that there is a huge difference between ('') and (") – user1940012 Dec 31 '12 at 21:05