[Python] NameError: name 'List' is not defined

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    def totalFruit(self, tree: List[int]) -> int:
    pass


    If I try importing List first I get an error No module named 'List'. I'm using Python 3.7.3 from Anaconda.

    Continue reading...

Compartilhe esta Página