search

Home  >  Q&A  >  body text

There is an arrow after the python function name. What does this do?

async def fetch(self, url: str, keys: object, repeat: int) -> (int, object):
    dosomething()
    return None  
    

I found such a statement when I was looking at other people's programs. I checked many places but couldn't find any explanation about "->".
The most similar ones found are arrow functions, but they look different.

What symbol is this? Or where should I check?

大家讲道理大家讲道理2750 days ago987

reply all(6)I'll reply

  • 世界只因有你

    世界只因有你2017-05-18 11:02:48

    Function annotations ?
    "Python 3 provides syntax to attach metadata to the parameters of a function declaration
    and its return value."

    reply
    0
  • 某草草

    某草草2017-05-18 11:02:48

    Stackoverflow has it.
    What does -> mean in Python function definitions?

    Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values.

    Simply put -> It is to tell the user the specific parameters and parameter types.

    For details, please see: PEP3107
    https://www.python.org/dev/pe...

    reply
    0
  • 高洛峰

    高洛峰2017-05-18 11:02:48

    Just prompt the function’s input parameters and return value数据类型

    Easy for programmers to read code.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-18 11:02:48

    http://python3-cookbook.readt...

    The python cookbook has a detailed description. It is recommended to read this book when you have time. It is still very helpful.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-18 11:02:48

    This is it. . . Prompt for return value type?

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-18 11:02:48

    This is a type hint that has been officially included since python3.5. It marks the type of variables. For IDEs supported by pycharm, it can provide more accurate code hints and variable inspections.

    For specific usage, please see https://docs.python.org/3/lib...

    reply
    0
  • Cancelreply