def fun_1(self, nums: List[int]) -> List[int]:

class Solution:
    def fun_1(self, nums: List[int]) -> List[int]:
        pass

其中def fun_1(self, nums: List[int]) -> List[int]:比较疑惑,查了查资料,发现这叫类型提示,3.5版本的新语法。
你写错了也不会影响程序运行,但是当然不建议这么做

def greeting(name: str) -> str:
    return 'Hello ' + name

greeting 函数中,参数name的类型是str,返回类型也是str。

posted @ 2022-12-12 13:43  辛宣  阅读(79)  评论(0)    收藏  举报