0
I’m new to programming and I’m following Eric Matthes' book exercises. In the text editor, I typed print = ('Hello,' + full_name.title() + '!')
and an error message appeared.
0
I’m new to programming and I’m following Eric Matthes' book exercises. In the text editor, I typed print = ('Hello,' + full_name.title() + '!')
and an error message appeared.
1
In python 2 print
is a language statement, not an object, or is to use 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 the ^
points the equals sign to be the syntax error, ie if you want to use this as 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, just remove the signal from =
and use as used on the other line:
print full_name
print 'Hello,' + full_name.title() + '!'
0
print
if it is a language statement, the error is happening because when you use the assignment operator (=
) trying to attribute something to print
, the interpreter understands that this is a syntax error (SyntaxError
).
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() + "!" )
Exit:
Ada Lovelace
ADA LOVELACE
ada lovelace
ada lovelace
Hello, Ada Lovelace!
Browser other questions tagged python python-2.7
You are not signed in. Login or sign up in order to post.
And what was the error message?
– Woss
This here: print = 'Hello,' + full_name.title() + '!' Syntaxerror: invalid syntax
– Giuseppe Lira
Is it python3? Or is it Python 2?
– Guilherme Nascimento
It seems to me that it is running on Python 2, not on 3, so, in fact, it is wrong. The problem is on
=
after theprint
. In Python 2, theprint
is a language statement and does not allow attribution. The correct isprint 'Hello'
, nayprint = 'Hello'
.– Woss
is Python 2.7.15. I wonder if this is it?
– Giuseppe Lira
Well, in this case I will search how I update python and try to run the program again. I warn you what happened. Thank you.
– Giuseppe Lira