How to specify argument type in a dynamically typed language, i.e. Python?

后端 未结 5 1640
甜味超标
甜味超标 2021-01-23 13:11

Is there any such equivalent of Java

String myMethod (MyClass argument) {...}

in Python?

Thank you, Tomas

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 13:38

    Python 3.x has function annotations where you can declare argument and return types:

    def myMethod(argument: MyClass) -> str:
       ...
    

    But currently Python does nothing with them, they serve as documentation only.

提交回复
热议问题