Exception Attributes
SyntaxError.lineno — exception attribute
Locate the starting source line of a syntax diagnostic. Lines are numbered from one, not zero. The position reports where parsing detected a problem, not necessarily the root cause.
Formal Syntax & Structure
python syntaxpython
error.linenoReturn Value
int | None
Diagnostic field when available.
Working Example
Example Snippetpython
error = SyntaxError("expected expression", ("demo.py", 3, 5, "x = ?\n", 3, 6))print(error.lineno)