Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python SyntaxError: invalid syntax for a valid statement

I have created a MWE:

x = True
if x:
    print('111111')
y = 1

When running in python interactive mode, I get

>>> x = True
>>> if x:
...     print('111111')
... y = 1
  File "<stdin>", line 3
    y = 1
    ^
SyntaxError: invalid syntax
>>>

The code looks very correct. If I add them line by line, they will be fine but now when copying them all together.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is wrong?

>Solution :

The interpreter is saying that the indentation of the second statement y=1 was unexpected.You should have entered a blank line to end the first statement (i.e., "if") , before you start writing the next statements(i.e y=1).

>>> x=True
>>> if x:
...     print('1111')
...
1111
>>> y=1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading