What would the following code generate?
mydict = ["name":"John", "surname":"Smith"]
print(mydict)
A SyntaxError
A SyntaxError would be generated because when you start with square brackets Python thinks you are about to define a list, but then you use colons instead of commas so that is not the correct syntax to define a list, thus the SyntaxError.
Here's one more challenge. What would the code generate this time?
a = [1, 2, 3}
A SyntaxError
Again you would get a SyntaxError because Python thinks you are about to define a list since you start with square brackets but then you close the array with a curly brackets which does not follow the Python syntax rules.
What would the below code output?
print(John)
A NameError
You would get a NameError because variable name John was not defined in the code. Don't confuse variable names with strings. Strings have quotes, variable names don't.
What would you get this time?
mylist = [John, Jack, Jim]
print(mylist)
A NameError
You would get a NameError again because John, Jack, and Jim names were not defined in the script. So, as soon as Python detects that John was not defined, it interrupts the code with a NameError and it doesn't even check the rest of the code.