SyntaxError: unexpected character after line continuation character in Python

Dung Do Tien Apr 17 2022 28

Hello Guys, I'm just starting to learn Python yesterday. I learn Input/output in Python first. I used print() method to help print many lines as below:

 name = input("Enter your name:")
print("Welcome, " + name + "to Python basic course. \n" \+
        "You need to Identity first, please enter your username: \n")
username = input("")
message = "Authentication failt"
if username == "admin":
    message = "Authentication OK!!!"
print(message)

I feel it's very simple but when running this code I got an error SyntaxError: unexpected character after line continuation character

 File "main.py", line 2
    print("Welcome, " + name + "to Python basic course. \n" \+
                                                             ^
SyntaxError: unexpected character after line continuation character

Not sure why and clear about it. Need someone who can help explain.

I used Python 3.9.9 and Windows 11.

Thanks for any explanation.

Have 1 answer(s) found.
  • M

    Mahmoud Samir Apr 17 2022

    To break lines in Python you have to use \ not \+

    Please change line 2 in your code.

     name = input("Enter your name:")
    print("Welcome, " + name + "to Python basic course. \n" \
            "You need to Identity first, please enter your username: \n")
    username = input("")
    message = "Authentication failt"
    if username == "admin":
        message = "Authentication OK!!!"
    print(message)

    #Output

     Enter your name:
    Ether
    Welcome, Etherto Python basic course. 
    You need to Identity first, please enter your username: 
    
    admin
    Authentication OK!!!
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close