1 | initial version |
One method to ensure that the input types declared for a function are checked is to use conditional statements to check the type of the input argument. For example:
def add_numbers(num1, num2):
if type(num1) == int and type(num2) == int:
return num1 + num2
else:
raise TypeError("Both inputs must be integers")
In this example, the function checks if both inputs are integers using the type()
function and raises a TypeError
if either input is not an integer. This ensures that the input types declared for the function are checked without using the check-type
function.