I在python3中找到如下代码:
def twoSum(self, nums: List[int], target: int) -> List[int]:
return sum(nums)
据我所知,对于 python def
,我们只需要遵循:
def twoSum(self, nums, target):
return sum(nums)
nums: List[int], target: int
和 ->List[int]
是什么意思?那些是python 3的新特性?我从没见过那些。
谢谢,
原文由 jason 发布,翻译遵循 CC BY-SA 4.0 许可协议
链接: https ://docs.python.org/3/library/typing.html
注意 Python 运行时不强制执行函数和变量类型注释。它们可以被第三方工具使用,例如类型检查器、IDE、linters 等。
链接: https ://code.visualstudio.com/docs/python/linting