Why statement 3 does not work while statement 1 does?
Because, in the first statement, we are assigning some constant to a variable. Variable assignment is simple enough such that we can keep on putting multiple constants to a single variable and the assignment will still go through. The terms "hello"
and "world"
are two constants of same type. So, the statement worked.
If we do the following, we will get SyntaxError
string1 = "Hello" 1
The reason is that we supplied multiple constants in a single variable assignment. This confused python and it thrown it out as an error.
The statement 3 is all about assigning a variable based on two variables. This will produce SyntaxError
as python don't know what it can do with 2 variables before assigning it to the variable.
Is there any technical difference such as calculation speed etc. between statement 1 and 2?
Yes. The only technical difference is readability rather than anything else. Readability matters most in Python. For an untrained eye, "hello" "world"
might look like the compiler would add the space to the strings. Which is not the case.
However,
"hello" + "world"
is explicit and normal. Nearly always, Explicit is better than implicit.