What does -> mean in Python function definitions?
In Python, the "->" symbol is used to indicate the return type of a function.
In Python, the "->" symbol is used to indicate the return type of a function. It is part of the function definition in a Python 3.5 or later. For example, the following code defines a function add that takes in two arguments, a and b, and returns the sum of the two arguments.
Using arrows in function definitions in Python
def add(a: int, b: int) -> int:
return a + b
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
The -> int at the end of the function definition indicates that the function returns an integer. This is known as type hinting and is used to help with code readability and debugging. Please note that this feature is not enforced in Python and it's just used as a hint for developer and IDEs.