讨论/综合讨论/Python指定函数参数、返回值类型报错是咋了?/
Python指定函数参数、返回值类型报错是咋了?

Leetcode刷题给的默认函数格式是这样的:
Class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
但是我拷贝到本地执行的时候出现了NameError
Traceback (most recent call last):
File "D:/PycharmProjects/untitled/venv/零钱兑换.py", line 1, in <module>
class Solution:
File "D:/PycharmProjects/untitled/venv/零钱兑换.py", line 2, in Solution
def coinChange(self, coins: List[int], amount: int) -> int:
NameError: name 'List' is not defined

产出指定类型后就没问题了
Class Solution:
def coinChange(self, coins, amount):

我百度了一下,给函数指定参数类型、返回值类型是Python 3.5以后默认的特性,为啥我会报错呢?
我用的是Python 3.7.2, PyCharm Community Edition 2019.3.3
求解惑!

展开讨论

from typing import List 在第一行加上,就好了。