For a single statement, I can do this:
if 1: print("hello")
The output:
hello
But when I tried something like this:
if 1: print("hello") print("end")
I got an error:
File "<stdin>", line 1
if 1: print("hello") print("end")
^
SyntaxError: invalid syntax
Why there is a syntax error? What is the right way to write multiple execution statement in single line with the if
condition? I want to print the "hello" and "end" when the condition is satisfied.
I want a single-liner for the following statement:
if 1:
print("hello")
print("end")