Binary operations in Python can be performed over operands of different data types in Python as long as types are compatible. For example,
a = 1 + 3.14
is fine, but
a = 1 + “Hello, world”
will throw a TypeError. In case when operands have different data types, more narrow one will be automatically converted to a wider data type. In previous example integer 1 will be converted to its float representation and added to 3.14 providing a float result.
Login in to like
Login in to comment