+ 1
Plz giv me a a little more simplified answer for '5' + 2 (why error)
8 Réponses
+ 11
I'm not a python developer, but I think what's happening is that '5' is a string and 2 is an int. It can't decide what to do with them, concatenate (52) or mathematically add them (7).
You need to convert '5' to an int or 2 to string, depending what you want as a result. For result of (52) convert 2 to string, for result (7) convert '5' to int.
http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python
Hope I helped! :)
+ 3
Your '5' is a string and 2 is an int.
You cannot sum them :-)
+ 2
When you put brackets "5" or '5' Python thinks that this is a word not a number
+ 1
got an idea.. thank u
0
because '5' is not integer. int + string = error. Python dosent work like php
0
convert str '5' to int, or int 5 to str.
0
Yaa '5' this is assumed as string and 2 is an integer number... So not performes the mathematical operation
0
an error arouses whenever You try to concatenate a string with an integer or simply two variables not of the same type
here Python has a tendency to take everything as a string present in between the " " or ' ' quotes
In this case it takes '5' as a string while 2 is an integer to solve this problem write instead
>>>print ('5' + str(2)) This would serve your purpose