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:
Copyint 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:
Copydef multiply(x: int, y: int) -> int:
return x*y
Answer from dreichler on Stack OverflowIn 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:
Copyint 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:
Copydef multiply(x: int, y: int) -> int:
return x*y
The signature indicates the names and types of the input arguments, and (with type annotations) the type of the returned result(s) of a function or method.
This is not particular to Python, though the concept is more central in some other languages (like C++, where the same method name can exist with multiple signatures, and the types of the input arguments determine which one will be called).
Documenting `__signature__`? - Documentation - Discussions on Python.org
Using / and * in Python function signatures
Helping people understand function signature syntax - Documentation - Discussions on Python.org
What is the significance of a single, lone asterisk in a functions documentation?
Videos
Hi everyone,
I've been exploring the use of / and * in Python function signatures to specify positional-only and keyword-only arguments. I understand the syntax, but I'm curious about their practical implications and best practices. I am coding for more than two years now and have never used them myself and i see them really rarely. That's why would like to learn about others experiance and maybe get some advice when it is appropriate to use them in my own functions?
Looking forward to your insights! Thanks!