0

Every time I try to run these first 2 lines in python, it says:

SyntaxError: invalid syntax

And highlights the name of the variable I'm trying to define (Yname).

These are the lines I'm trying to run:

print("Hello what's your name?")\       
Yname = input("your name:")
K DawG
  • 13,287
  • 9
  • 35
  • 66
  • 1
    Why do you have the backslash in there? Just take it out. – BrenBarn Jun 16 '14 at 03:16
  • possible duplicate of [error in python d not defined](http://stackoverflow.com/questions/2612948/error-in-python-d-not-defined) – Aamir Rind Jun 16 '14 at 03:17
  • remove '\' from first line – rock321987 Jun 16 '14 at 03:19
  • 2
    @AamirAdnan Because he's getting a `SyntaxError`, not a `NameError`, I don't think this problem is a dupe of that (though he may very well run into that error soon). However, this question should still be closed as Off-topic/typographical error. – dano Jun 16 '14 at 03:20
  • @dano there was an empty line in between two line of code and the line continuation '\' was not the problem until @sharth edited it so before I thought the OP might having `NameError`. – Aamir Rind Jun 16 '14 at 03:23
  • "SyntaxError: multiple statements found while compiling a single statement" I took out the backslash and then got this, what am I doing wrong? – user3743359 Jun 16 '14 at 03:34

1 Answers1

5

It is because of the \ at the end of the first line. in Python \ is the line continuation character. Python is trying to parse this as

print("Hello what's your name?")Yname = input("your name:")
XrXr
  • 2,027
  • 1
  • 14
  • 20
  • +1 -- I think that showing it this way (as python is trying to parse it) also nicely demonstrates _why_ the `SyntaxError` pointed at `Yname` when really the problem exists on the previous line to the human eye. – mgilson Jun 16 '14 at 03:21