Python error writing good syntax in program

Asked By 0 points N/A Posted on -
qa-featured

Hi there,

This error tells me that I have entered an invalid syntax. I am a newbie using Python but I have followed a tutorial and this syntax worked just fine there. Can anyone tell me please what I did wrong ? Why is not working like in the tutorial ?

Thanks !

Syntax error

There’s an error in your program: invalid syntax.

SHARE
Answered By 573100 points N/A #179429

Python error writing good syntax in program

qa-featured

You followed the tutorial, alright, but the way you typed the command to display “blah blah” on the screen is incorrect and that causes the syntax error. To print a text on the screen or to display a message using the print statement in Python, the text to be printed should be enclosed in double quotes and ending the line with a semicolon. For example:

  • Print “First time on Python.”;

This line, when executed in Python, will display the message:

  • First time on Python.

If you are using Python 2.4.3, this is how you properly write or use the print statement. But if you are using the new version of Python or the latest version, the message together with the quotes should be enclosed inside a parenthesis. When using a new version, the command or line above will be written as:

  • Print (“First time on Python.”);

The line is also terminated with a semicolon and will have the same output message as displayed above. So, to fix your problem, that line should be written as:

  • Print “blah blah”;

Or:

  • Print (“blah blah”);

Login/Register to Answer

Related Questions