python - Error "Can't convert 'int' object to str implicitly" -
this question has answer here:
i started automate boring stuff, i'm @ chapter 1.
myname = input() print ('it nice meet you,' + myname) lengthofname = len(myname) print ('your name many letters:' + lengthofname)
i ran this, gave me can't convert 'int' object str implicitly
. reasoning @ line 3 want variable myname
converted integer , plugged line 4.
why erroneous way of coding?
you have problem because +
can add 2 numbers or concatenate 2 strings - , have string + number
have convert number string before can concatenate 2 strings - string + str(number)
print('your name many letters:' + str(lengthofname))
but can run print()
many arguments separated comma - in other functions - , python automatically convert them string before print()
displays them.
print('your name many letters:', lengthofname)
you have remeber print
add space between arguments.
(you "comma adds space" print it.)
Comments
Post a Comment