Visual Studio python says else is invalid syntax and is unknown

Viewed 166

I am writing code in python on the visual studio code IDE with the python extension installed.

There this a part of my code that is :

if newuser == "":
    #error 0 code
else:
    return 

And the else: is underlined in red as an error and says

invalid syntax (, line 153)pylint(syntax-error)

I have other if statements in my code that work but it is just this one

1 Answers

If you have an empty statement, Python will throw an error unless you use pass.

if newuser == "":
    pass
else:
    return 

A better way of writing the code is just to use != (meaning 'is not equal to') rather than == like below:

if newuser != "":
    return
Related