Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a function signature?

I was studying python and I ran into the concept of 'signature'. I looked things up but signature of a function seems to have different meaning for different languages. So, what does signature of a function refer to in python?

like image 994
Hajin Lee Avatar asked Feb 20 '26 12:02

Hajin Lee


1 Answers

In general the signature of a function is defined by the number and type of input arguments the function takes and the type of the result the function returns.

As an example in C++ consider the following function:

int multiply(int x, int y){
    return x*y;
}

The signature of that function, described in an abstract way would be the set {int, int, int}.

As Python is a weakly typed language in general the signature is only given by the amount of parameters. But in newer Python versions type hints were introduced which clarify the signature:

def multiply(x: int, y: int) -> int:
    return x*y
like image 124
dreichler Avatar answered Feb 22 '26 03:02

dreichler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!