5

Python3 中的 List[int] 使用的是 typing 模块么?

 2 years ago
source link: https://www.v2ex.com/t/825852
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

Python3 中的 List[int] 使用的是 typing 模块么?

  Deteriorator · 10 小时 28 分钟前 · 425 次点击

leetcode 中的 Python3(python3.9.5) 语言在选择的时候会自动生成一部分代码,参数类型中有 List[int] 类型。

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

但是我在本地 Pycharm 中运行的时候会找不到 List

NameError: name 'List' is not defined

导入 typing 后就正常了

from typing import List

leetcode 是在运行代码之前导入了这个模块么? 在提交代码的时候, 代码中并没有 typing 模块相关的信息


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK