1

So I'm just starting to learn Python through Code Academy. In the course, it teaches that using triple quotes (double or single) allows for, "multi-line" strings. In the compiler for their website, the following code was entered and it worked:

Using Multi-Line strings in Code Academy Python

As you can see, the code works perfectly fine when saved to a variable and being asked to print it. I decided to try this out on Visual Studio Code however, and now there is a SyntaxError.

quote = """
My name is William Pak
and I like to play games
"""

print("quote)

Upon running this on Visual Studio Code, the following error shows up:

>>> & C:/Users/Willi/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Willi/OneDrive/Documents/GitHub/BlockLetters/initials.py
  File "<stdin>", line 1
    & C:/Users/Willi/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Willi/OneDrive/Documents/GitHub/BlockLetters/initials.py
    ^
SyntaxError: invalid syntax

Can somebody explain to me exactly what is happening and why it isn't even allowing me to do this on Visual Studio Code, but it allows for me to do it on Code Academy's compiler?

P.S (This is my first ever question on stack overflow so I apologize if my question isn't written or explained well enough for you to understand.)

2

2 Answers 2

3

If you remove the quotation mark in the last line your code works:

quote = """
My name is William Pak
and I like to play games
"""

print(quote)

output:


My name is William Pak  
and I like to play games

Sign up to request clarification or add additional context in comments.

1 Comment

Oh lol. It was just a simple typo that made it all mess up. Thanks so much for your help!
1

yes ,that is true you can use triple quote for multi lines string but your print code is not correct it is better to use

print(quote)

and your output will be change to

My name is William Pak
and I like to play games

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.