I'm new to programming and I'm following the exercises in Eric Matthes's book. In the text editor, I typed print = ('Hello,' + full_name.title() + '!')
and an error message appeared.
In python 2 print
is a declaration of language, not an object, ie using the equal operator =
doing with print as if it were a variable will cause error:
Traceback (most recent call last):
File "python", line 14
print = 'Hello,' + full_name.title() + '!'
^
SyntaxError: invalid syntax
See that ^
points to the equal sign as the syntax error, ie if you want to use this as a variable then use a name other than a "function" or reserved word, create an intuitive var, for example:
msg = 'Hello,' + full_name.title() + '!'
Now if the intention is to display , simply remove the sign from =
and use as you used on the other line:
print full_name
print 'Hello,' + full_name.title() + '!'
print
This is a language statement, the error is happening because when you use the assignment operator ( =
) trying to assign something to print
, the interpreter understands that this is a syntax (% with%).
Maybe you want something like:
name = "ada lovelace"
print( name.title() )
print( name.upper() )
print( name.lower() )
first_name = "ada"
last_name = "lovelace"
full_name = first_name + " " + last_name
print( full_name )
print( "Hello, " + full_name.title() + "!" )
Output:
Ada Lovelace
ADA LOVELACE
ada lovelace
ada lovelace
Hello, Ada Lovelace!