From the Python grammar, we can see that ; is not defined as \n. The parser expects another statement after a ;, except if there’s a newline after it:
Semicolon w/ statement Maybe a semicolon Newline
\/ \/ \/ \/
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
That’s why x=42;; doesn’t work; because there isn’t a statement between the two semicolons, as “nothing” isn’t a statement. If there was any complete statement between them, like a pass or even just a 0, the code would work.
x = 42;0; # Fine
x = 42;pass; # Fine
x = 42;; # Syntax error
if x == 42:; print("Yes") # Syntax error - "if x == 42:" isn't a complete statement