Python is a programming language which is famous for its polymorphism. It means that the same operation will work differently with objects of different data types. It’s very useful but in some cases can lead to unexpected behaviour of your code. Let’s imagine, that you’ve sent a request and have got a response. You expected to get two numbers a=1 and b=2, and you were going to calculate their sum (a+b=3). But you’ve received the same numbers in form of strings (a=”1" and b=”2"). Then a+b=”12". In this case your code will work, but the answer is incorrect. What can be done in this case? You should assure that the variables have expected data types, and if they do not, change them.
Let’s consider the situation using the described case, but in form of function which gets two arguments and allows to calculate their sum: