"7" + 1 should be 71 Why Python occur an exception? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

"7" + 1 should be 71 Why Python occur an exception?

17th Dec 2015, 12:35 PM
Mahmud Al Hakim
Mahmud Al Hakim - avatar
7 Answers
+ 2
you can't add two operands with different types
9th Feb 2016, 4:55 AM
Amgd Gocha
Amgd Gocha - avatar
+ 1
Plus sign joins strings but in this case the number 1 is an integer. You should do "7" + str(1) to get '71'
23rd Dec 2015, 7:12 PM
Marcos Chimeno
Marcos Chimeno - avatar
+ 1
you are trying to add numbers with string. it does not work in python , if trying to multiply string to an integer, oh yes , all right
29th Jan 2016, 1:07 PM
Emanuel
Emanuel - avatar
+ 1
"7" is string and 1 is number. so it can't be added by + operands.
28th Jun 2016, 1:20 PM
husen
husen - avatar
+ 1
Python won't implicitly coerce types on must cases, string addition is one of those.
29th Jun 2016, 9:38 PM
Edgar Garrido
Edgar Garrido - avatar
+ 1
if you want to add string and integer you can use: str(value)+ int_value.
8th Jul 2016, 4:20 PM
Shantam Vijayputra
Shantam Vijayputra - avatar
0
Thanks for good answers. In many other languages like JavaScript you can and string to number implicitly.
22nd Oct 2016, 1:37 PM
Mahmud Al Hakim
Mahmud Al Hakim - avatar