Is python3 supports automatic type conversion between data types ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Is python3 supports automatic type conversion between data types ?

9th Jun 2017, 6:25 PM
kate Wilson
kate Wilson - avatar
3 Answers
+ 14
Yes, it does support automatic type-conversion (i.e., implicit data conversion) between limited data-types! For example : numerical values (integer, float, long, complex numbers) get inter-converted to the data type with higher precedence [int < float < long < complex number] Similarly, you can add a string to another string! But if you're to add a string to an int or int to string, you'll get TypeError! But if you would multiply an integer to a string, you'll have the string output that's repeated to the given times the integer! Note : There's no 'double' data type in Python!
10th Jun 2017, 12:10 PM
Harshit Gupta
Harshit Gupta - avatar
+ 6
print(1 + "2") # TypeError: unsupported operand type(s) for +: 'int' and 'str' print(1 + 1.0) # int + float 2.0 # a float Sometimes/Not always?
9th Jun 2017, 7:18 PM
Kirk Schafer
Kirk Schafer - avatar
+ 5
thanks @harshit and @kirk
10th Jun 2017, 2:10 PM
kate Wilson
kate Wilson - avatar