What does this program print? Pay close attention to spaces.
print("Hello", "World", "!")
Write three versions of the hello.py program that have different compile-time errors.
The program you provided:
print("Hello", "World", "!")
will print:
Hello World !
Notice that there are spaces between the words "Hello", "World", and the exclamation mark "!" because the print
function in Python separates its arguments with a space by default.
Now, here are three versions of the hello.py
program that contain different compile-time errors:
print("Hello" "World" "!")
Error: This will raise a SyntaxError
because the strings are not properly separated by commas.
print "Hello", "World", "!"
Error: This will raise a SyntaxError
in Python 3 because the print
statement requires parentheses.
1st_variable = "Hello"
print(1st_variable, "World", "!")
Error: This will raise a SyntaxError
because variable names cannot start with a digit.
These examples illustrate different types of compile-time errors that can occur in Python.