+ 2

Type conversion

Why isn’t it 7. I thought the explanation said print(int(“3”+”4”) would be 7?? Am I just hallucinating or what??

2nd Feb 2020, 8:49 PM
00._.Chewy._.00
00._.Chewy._.00 - avatar
4 ответов
+ 9
int("3"+"4") = int("34") = 34 int("3")+int("4") = 3+4 = 7
2nd Feb 2020, 8:53 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
thanks heaps that makes sense now i was just a bit confused!!
2nd Feb 2020, 8:56 PM
00._.Chewy._.00
00._.Chewy._.00 - avatar
+ 1
Calculations with parentheses from the innermost set outwards, like in maths!
3rd Feb 2020, 12:16 AM
HonFu
HonFu - avatar
0
here in the code print(int(“3”+”4”) 3 and 4 are converted to string due to being enclosed in double quote, and + operator is concatenating those string to 34.and again it is converted to integer type by using explicit type conversion of int(parameter/expression) thus, if you are wanting to print 3+4=7 try just print(3+7)
5th Feb 2020, 12:01 PM
Sumit Kumar Singh
Sumit Kumar Singh - avatar