invalid syntax on Quote from person in python

Viewed 56

hello I'm learning python. I want to use Quote from person in my Sentence but I see this Error. How can I solve it? I write my code down line:

sentence='shiva said:'I am\n programmer''
print(sentence)

and my Error is: invalid syntax

1 Answers

Strings in Python can use double quotes or single quotes. If you want single quotes in the sentence you can use double quotes:

sentence = "shiva said:'I am\n programmer'"

You can also just escape the single quotes by preceding with a backslash. This tells Python to not treat the following single quote as the end of the string.

sentence = 'shiva said:\'I am\n programmer\''

Triple quotes are also available (both types) and can span multiple lines:

sentence = """shiva said 'I am
programmer'"""
Related