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?

1
  • 1
    You can also use ''' or """ if you absolutely hate backslashes (as you should :). ie. '''"Isn't this cool?"'''
    – Derek Litz
    Dec 31, 2012 at 18:55

6 Answers 6

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

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'")
0
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!

1
  • This is the same as what's already mentioned in earlier answers. Dec 19, 2021 at 12:22
0

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

0
-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 ".

2
  • 2
    I think the other 5 answers also contain this information. What is new in this answer?
    – wovano
    Oct 1, 2021 at 11:00
  • Hi I took all together. because it's easier to see. but you're right, i will correct my work
    – Mahdi Ebi
    Oct 14, 2021 at 20:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.