Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Eg.

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

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

I get an invalid syntax error. How to fix this?

1 Answer

0 votes
by (106k points)

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

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...