Type conversion | SoloLearn: Learn to code for FREE!


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??

2/2/2020 8:49:32 PM


4 Answers

New Answer


int("3"+"4") = int("34") = 34 int("3")+int("4") = 3+4 = 7


thanks heaps that makes sense now i was just a bit confused!!


Calculations with parentheses from the innermost set outwards, like in maths!


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)