Strong typing in Python

The strength of the type system, on the other hand, can be demonstrated by attempting to add() types for which addition has not been defined, such as strings and floats:

>>> add("The answer is", 42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in add
TypeError: Can't convert 'int' object to str implicitly

Trying to do this results in a TypeError because Python will not, in general, perform implicit conversions between object types or otherwise attempt to coerce one type to another. The primary exception to this is the conversion to bool used for if statement and while-loop predicates. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset