code documentation Flashcards
1
Q
call signatures
A
The signature() function in Python, is used to find the signature of a function.
from inspect import signature
#defining our function
def addition(a:int, b:int):
ans= a + b
return ans
#calling our function
print(“The answer is =”,addition(3,5))
#printing the input parameters of the function
sig = signature(addition)
print(sig)
#printing type of a
print(sig.parameters[‘a’])
#printing annotation of b
print(sig.parameters[‘b’].annotation)
The output would be:
The answer is = 8
(a: int, b: int)
a: int
<class ‘int’>
**This function will raise a TypeError if the class of the object or the object type is invalid.