Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python restrict function parameter type

def add(a:int, b:int, c:int=0) -> int:
    """ Add 2 or 3 integers and return an integer result.
    """
    for var in [a, b, c]:        
        if not isinstance(var, int) :
            raise TypeError('Please make sure all inputs are integers')
    result = a + b + c
    return result
 
PREVIOUS NEXT
Tagged: #python #restrict #function #parameter #type
ADD COMMENT
Topic
Name
3+2 =