NameError: name 'List' is not defined

后端 未结 3 859
情深已故
情深已故 2020-12-29 18:01

I\'m really unsure why this isn\'t working. Here is the important part of the code (it\'s from a leetcode challenge). The first line throws the NameError.



        
3条回答
  •  一生所求
    2020-12-29 18:49

    To be able to annotate what types your list should accept, you need to use typing.List

    from typing import List
    

    So did you import List?

    Update

    If you're using Python 3.9, see @Adam.Er8's answer

提交回复
热议问题