Reputation: 41
How can I use single quote and double quote same time as string python? For example:
string = "Let's print "Happines" out"
result should be Let's print "Happines"
out
I tried to use backslash but it prints out a \
before 's that should be.
Upvotes: 0
Views: 2436
Reputation: 26570
Taking this string:
string = "Let's print "Happines" out"
If you want to mix quotes, use the triple single quotes:
>>> string = '''Let's print "Happines" out'''
>>> print(string)
Let's print "Happines" out
Using triple quotes is acceptable too:
>>> string = """Let's print "Happines" out"""
>>> print(string)
Let's print "Happines" out
Upvotes: 1
Reputation: 6633
In python there's lots of ways to write string literals.
For this example you can:
print('Let\'s print "Happiness" out')
print("Let's print \"Happiness\" out")
print('''Let's print "Happiness" out''')
print("""Let's print "Happiness" out""")
Any of the above will behave as expected.
Upvotes: 2