This is a syntax I see in Python3 code skeletons on leetcode.com. Note the type declarations of the function input arguments (or at least I think they're type declarations, never seen it before). nums
must be a List
of int
, and s
must be an int
.
class Solution:
def findTargetSumWays(self, nums: List[int], S: int) -> int:
pass
If I run that function inside the environment on leetcode.com, it exits without error. However, if I run the same code in my own Python 3.7.3 environment, I get a NameError.
def findTargetSumWays(self, nums: List[int], S: int) -> int: NameError: name 'List' is not defined
What is wrong? Is the syntax on leetcode.com even real Python?