+ 8
Is python3 supports automatic type conversion between data types ?
3 Respuestas
+ 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!
+ 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?
+ 5
thanks @harshit and @kirk