Microsoft’s Python team released Pylance in early 2018 to support Python IntelliSense in Visual Studio Code. “Statements must be separated by newlines or semicolons” is a hint message when coding in Pylance. Therefore, this message appears only when you code Python in Visual Studio Code. This article will explain this message and discuss how to avoid it while programming.
When does the message “Statements must be separated by newlines or semicolons” appear?
This error happens when you attempt to run two Python commands on the same line without properly separating them. This indicates that the code missing newlines or semicolons between statements. For example, If you use two print commands on the same line, VScode will display this message in the PROBLEMS tab.
name = 'LearnShareIT' url = 'learnshareit.com' # Use 2 print commands on the same line print(name) print(url)
In VScode’s PROBLEMS tab:

If you try to run the code, Python will throw the following error:
print(name) print(url)
^
SyntaxError: invalid syntax
This problem can also occur if you forget to use round brackets in the print statement. As an example:
name = 'LearnShareIT' url = 'learnshareit.com' # Use the print command without the round brackets print name
PROBLEMS:

Error:
print name
^
SyntaxError: Missing parentheses in call to 'print'
How to fix this problem?
Using the correct syntax
If you get this problem, you’re attempting to write multiple lines of code without following proper syntax. Double-check your code to ensure you’re using the correct Python syntax when you receive this message. In our example, make sure to use the correct print function syntax. The print function must include parentheses.
name = 'LearnShareIT' url = 'learnshareit.com' # Use the correct syntax of print() print(name)
PROBLEMS:
No problems have been detected in the workspace.
Output:
LearnShareIT
Using a newline or semicolon
We can also use a newline or semicolon to correct this problem. This tells Python that you want the code to be executed in separate statements. To do this, simply press the enter key after each line of code or use semicolons to separate statements on one line. For a better understanding, look at the two sample code snippets below.
name = 'LearnShareIT' url = 'learnshareit.com' # Use the newline to separate statements print(name) print(url)
PROBLEMS:
No problems have been detected in the workspace.
Output:
LearnShareIT
learnshareit.com
name = 'LearnShareIT' url = 'learnshareit.com' # Use the semicolon to separate statements print(name); print(url)
PROBLEMS:
No problems have been detected in the workspace.
Output:
LearnShareIT
learnshareit.com
Summary
When you encounter the problem “Statements must be separated by newlines or semicolons“, in that case, it may be because you copied and pasted code from another source without properly formatting it, or you tried to run Python code that’s not properly formatted. To correct this problem, read the message line and use newlines or semicolons where needed. Although a semicolon has the same results as a newline, we recommend using a newline to separate statements because it is a coding convention in Python.
Have a beautiful day!
Maybe you are interested:
- RuntimeWarning: Enable tracemalloc to get the object allocation traceback
- Unsupported operand type for *: builtin_function_or_method and float

Hi, I’m Cora Lopez. I have a passion for teaching programming languages such as Python, Java, Php, Javascript … I’m creating the free python course online. I hope this helps you in your learning journey.
Name of the university: HCMUE
Major: IT
Programming Languages: HTML/CSS/Javascript, PHP/sql/laravel, Python, Java