I am trying to learn Python and while doing an exercise this error showed. My code:
a = "Half of \nthis sentence."
b = "\tSo far away."
"""
print "Hi my name is %s" % 'Jonas'
It's the triple quotes but why? I was just trying to make a space empty under the line so I could have a gap between the two.
As it was already said, you have made a string which has no end.
To be honest, I don't really understand what you are trying to do by using this triple quote, so I can't provide the code you want. But keep in mind that:
Triple quotes are used in order to define a string.
You already know that "
means either the start or the end of a string. It is also the case for """
! So if you begin a sentence with """
, you have to close it with """
.
print """Hello"""
These triple quotes are useful in some cases, when you have to print some characters like "
or '
.
print """I have found the letter 'H' in the word "Hello"."""
They also have a certain feature; they allow to define long strings on several lines.
print """The width of my
screen prevents me from
writing long sentences."""
And that is why you get an error. The instruction print "Hi my name is %s" % 'Jonas'
is not actually interpretated as an instruction here, it is interpretated as the second line of a string, because it is located after the mark """
, which means that a string has begun. And this string is not even completely defined because the code lacks of the """
which marks the end of the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With